0

Why j is not incremented in below code?

#include<stdio.h> int main() { int i=-3, j=2, k=0, m; m = ++i || ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0; }

7th Jun 2019, 4:03 PM
Geek
Geek - avatar
5 Answers
+ 1
It's because it checked ++i, which turned out to be true, so it will definitely will be true, so to make it quicker it skips that part, therefore j isn't incremented
7th Jun 2019, 4:05 PM
Airree
Airree - avatar
+ 1
I'm pretty sure they have the same precedence
7th Jun 2019, 4:18 PM
Airree
Airree - avatar
+ 1
yes...++i gives the non zero value which means TRUE and in the OR operator if first statement is true the no need to see the other side...because if we see the truth table of or operator the we know why this is...lets see, true true= true and true false=true...hence we know that in both cases the ans is true...so we not check the second part operand because of first one is true...this is the reason ++j is not incremented as per my knowledge...
7th Jun 2019, 5:58 PM
Tushar Shekokar
Tushar Shekokar - avatar
0
As the precedence of "and" is greater, right hand side should be executed first?
7th Jun 2019, 4:10 PM
Geek
Geek - avatar
0
Ok thanks
7th Jun 2019, 6:42 PM
Geek
Geek - avatar