We have an expression
int x,y,z;
x=y=z=2;
y=++x || --y;
printf("%d %d",x,y);
It gives x=3
and y=2
as output but i think here we have 4 operators : ++
, --
, ||
and =
.
We know ++
and --
have the highest priority so they must be evaluated first, followed by ||
and then =
.
Also we know ++
and --
have the same priority so we use associativity, and in this case it is right to left. So I think first --y
will be evaluated which gives y=1
, then ++x
which should give x=3
and then ||
should be evaluated.
Why am I getting different answer from my machine? Thank You.