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

  • Thread starter Thread starter vorcil
  • Start date Start date
AI Thread Summary
The expression "if (iarray[i] < 0 && *isigned)" in C evaluates whether the element at index i in the array is less than 0 and whether the value pointed to by isigned is true (1). The logical AND operator (&&) means both conditions must be satisfied for the if statement to execute. It is clarified that this is not a looping statement; it only checks a single element of the array. If the first condition (iarray[i] < 0) is false, the second condition (*isigned) is not evaluated. Understanding this logic is crucial for correctly interpreting the code's behavior.
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
Views
3K
Replies
2
Views
2K
Replies
9
Views
9K
Replies
17
Views
2K
Replies
5
Views
2K
Replies
3
Views
1K
Replies
15
Views
2K
Replies
1
Views
1K
Back
Top