0

Explain it plzzz

#include <stdio.h> int main() { int x=0,y=0; if(x++&&y++) printf("x=%d y=%d",x,y); else printf("y=%d x=%d",y,x); return 0; }

15th Apr 2020, 7:23 AM
Siddhant Saxena
Siddhant Saxena - avatar
2 Respostas
+ 3
Here x++ is 0 which is false so it will not check second condition. So y = 0 because didn't check next condition. x = 1 because x is incremented by 1 after doing operation.
15th Apr 2020, 7:44 AM
A͢J
A͢J - avatar
0
in C, any number which is null has the boolean value 'False', else, it's 'True'. but x++ and y++ are postfix incrementation, so x and y will be tested first, before incrementing. to test if 'a and b' is true, if a is false, no need to test b, a and b is automatically false, if a is true, then a and b has the value of b in our case a=x++=0 which is false, (but after the test, x is incremented to 1) so no need to test y++ anymore. the if condition is not satisfied and it jumps to the esle statement where 'y=0 x=1' is printed https://www.sololearn.com/learn/C/2917/
15th Apr 2020, 7:44 AM
John Robotane
John Robotane - avatar