I was searching on Stack Overflow for the answer to this question but I haven't found an exact answer. I came up with this code. I know how operators are supposed to work but I don't understand them in this kind of problem. For example, in the first case, how can z
and y
still be 1 if there I am using ++y
and ++z
?
#include <stdio.h>
int main(void) {
int x, y, z;
x = y = z = 1;
++x || ++y && ++z;
printf("x = %d y = %d z = %d\n", x, y, z);
x = y = z = 1;
++x && ++y || ++z;
printf("x = %d y = %d z = %d\n", x, y, z);
x = y = z = 1;
++x && ++y && ++z;
printf("x = %d y = %d z = %d\n", x, y, z);
x = y = z = -1;
++x && ++y || ++z;
printf("x = %d y = %d z = %d\n", x, y, z);
x = y = z = -1;
++x || ++y && ++z;
printf("x = %d y = %d z = %d\n", x, y, z);
x = y = z = -1;
++x && ++y && ++z;
printf("x = %d y = %d z = %d\n", x, y, z);
return 0;
}
As results i get:
x = 2 y = 1 z = 1
x = 2 y = 2 z = 1
x = 2 y = 2 z = 2
x = 0 y = -1 z = 0
x = 0 y = 0 z = -1
x = 0 y = -1 z = -1