When evaluating a logical AND, if the first expression is zero / false means that it will not evaluate the remaining expression. So
z = ++x&&++y&&++z;
z=0;
Try the following code snippets -
int x, y, z,temp;
x = y = z= -1;
temp = ++x&&++y&&++z;
printf("x = %d y = %d z = %d temp= %d", x, y ,z,temp); // Output 0,-1,-1,0
x = y = z= -1;
temp = ++x || ++y&&++z; // But in Logical OR if first expression is true means it wont execute the remaining expression
printf("x = %d y = %d z = %d temp= %d", x, y ,z,temp); // Output 0,0,-1,0
x = y = z= -1;
temp = ++x || ++y || ++z;
printf("x = %d y = %d z = %d temp= %d", x, y ,z,temp); // Output 0,0,0,0
source
share