#include <stdio.h>
int main()
{
int x = 0, y = 0, z;
z = ++x || ++y;
printf("%d %d %d", x, y, z);
}
Yes, its output will be x=1, y=0, z=1. This happens because of optimisation: when "z = ++x || ++y;" is processed, x is being incremented and the entire expression is TRUE. As there is logical OR in this expression, further elements will be ignored for optimisation purposes.
You could also try to exchange the order: "z = ++y || ++x;", and ypu'll get the following result: x=0, y=1, z=1 - as you can see, same thing occured and x isn't incremented.
Comments
Leave a comment