Evaluating "iarray[i] < 0 && isigned" in C: Meaning Explained

  • Thread starter Thread starter vorcil
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on evaluating the C statement "if (iarray[i] < 0 && *isigned)". It clarifies that "isigned" is a pointer, and "*isigned" dereferences this pointer to obtain a value that is either 0 or 1. The logical AND operator (&&) evaluates the first condition, "iarray[i] < 0", before considering the value pointed to by "isigned". If the first condition is false, the second condition is not evaluated, making this a non-looping statement that checks a single element of the array.

PREREQUISITES
  • Understanding of C programming syntax and semantics
  • Knowledge of pointers and dereferencing in C
  • Familiarity with logical operators in C
  • Basic understanding of conditional statements in programming
NEXT STEPS
  • Study pointer arithmetic and memory management in C
  • Learn about logical operators and their precedence in C
  • Explore conditional statements and control flow in C programming
  • Review examples of array manipulation and evaluation in C
USEFUL FOR

C programmers, computer science students, and anyone looking to deepen their understanding of conditional statements and pointer usage in C.

vorcil
Messages
395
Reaction score
0

Homework Statement



in this statement

if (iarray < 0 && *isigned)

How do I evaluate that

the code is in c

isigned is either 0 or 1

does it mean that for each value in the array that is less than 0 AND for each value in the array that is less than isigned

or does it mean for each value in the array AND a some other statement

&& isigned (where isigned is either 0 or 1)

what does it mean?

Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
vorcil said:

Homework Statement



in this statement

if (iarray < 0 && *isigned)

How do I evaluate that

the code is in c

isigned is either 0 or 1

does it mean that for each value in the array that is less than 0 AND for each value in the array that is less than isigned

or does it mean for each value in the array AND a some other statement

&& isigned (where isigned is either 0 or 1)

what does it mean?
/b]


I would think isigned must be a pointer and *isigned is the value stored at the address pointed to. So it isn't isigned which is 0 or 1, it is that value at that address that is. The && operator performs a logical AND interpreting that 1 or 0 as TRUE or FALSE.
 
Cheers matey potatey
 
vorcil said:
if (iarray < 0 && *isigned)

How do I evaluate that

the code is in c

isigned is either 0 or 1

does it mean that for each value in the array that is less than 0 AND for each value in the array that is less than isigned

or does it mean for each value in the array AND a some other statement

&& isigned (where isigned is either 0 or 1)

what does it mean?

This is not a looping statement. This if statement looks at only one element in the array.

The && is performed last, after iarray < 0 is evaluated. So it's equal to:
if ((iarray < 0) && *isigned)

Also, unless the first condition evaluates as true, then whatever isigned points to is not considered. So isigned need not point anywhere, not until iarray < 0 becomes true (at least as far as evaluation of this statement is concerned).
 
Last edited:

Similar threads

  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 9 ·
Replies
9
Views
9K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
7
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K