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; }
5 odpowiedzi
+ 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
+ 1
I'm pretty sure they have the same precedence
+ 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...
0
As the precedence of "and" is greater, right hand side should be executed first?
0
Ok thanks