int x=0, y=0, z=0;
z = (x==1) && (y=2);
printf("%d ", y);
I'm wondering the output is 0. Why the output is not 2?
int x=0, y=0, z=0;
z = (x==1) && (y=2);
printf("%d ", y);
I'm wondering the output is 0. Why the output is not 2?
Because of how C deals with the logical operators:
Since x==1 returns "false", there is no need to check the RHS in order to conclude that the end result of the operator && is false. Hence, RHS is not evaluated and y stays at its previous value.