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

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

Discussion Overview

The discussion revolves around the evaluation of the C programming statement if (iarray[i] < 0 && *isigned). Participants explore the implications of the logical AND operator in this context, particularly focusing on the role of the variable isigned, which is described as a pointer that can point to a value of either 0 or 1.

Discussion Character

  • Homework-related
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant questions whether the statement evaluates each value in the array against both conditions or if it is a singular evaluation involving isigned.
  • Another participant suggests that isigned is a pointer and clarifies that *isigned refers to the value at the address it points to, interpreting the logical AND as combining boolean values.
  • A further response emphasizes that the if statement evaluates only one element of the array, indicating that the logical AND is applied after evaluating iarray[i] < 0.
  • This participant also notes that if the first condition is false, the evaluation of *isigned does not occur, implying short-circuit evaluation.

Areas of Agreement / Disagreement

Participants express different interpretations of the statement, with some focusing on the role of isigned as a pointer and others on the logical structure of the if statement. There is no consensus on a single interpretation, as multiple viewpoints are presented.

Contextual Notes

Some participants assume familiarity with pointer dereferencing and logical operations in C, which may limit the discussion's accessibility to those less experienced with these concepts.

Who May Find This Useful

Readers interested in C programming, particularly those learning about conditional statements and pointer usage, may find this discussion beneficial.

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
3K
  • · 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