int main()
  int a,b,c;
  c = ++a || ++b && ++c;
  printf("%d %d %d", a,b,c);

here the expression is considered from left to right.
but the confusion of mine is:

&& has got higher precedence than that of ||.
so ++b && ++c should be calculated first.
why it so happens that when ++a which is true is found the rest of the expression is not even considered.
i find the output as:
2 1 1
plz. help..

10 Years
Discussion Span
Last Post by gkbush

Because true OR true is always going to be true, and true OR false is always going to be true. Operator precedence does not necessarily mean operation precedence (that's not the right word, i just don't know how to explain it). That is, the AND will be evaluated before the OR, but the OR is still seen before the AND.



a will be set equal to the value that is in b.
Then b will be set equal to the value in c.
Last c will be set to 1.

This is the challenge of this type of statement.

Logic expressions are true when not equal to zero.
Even a negative number is considered true.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.