I got stuck in some coding.

Rakesh @_@

Right off the assembly line
Code:
#include<stdio.h>
void main()
{
int x, y, z;
x=y=z=1;
z = (++x || ++y && ++z);  //statement 1
printf("x = %d\ty = %d\tz = %d",x,y,z);
}

need help in understanding why y comes 1 instead of 2 according to me from statement 1.
 

Faun

Wahahaha~!
Staff member
Since there is || operation in the expression. And if the first expression to the left of || is true (i.e. non zero value) then the rest of the expression is assumed true without evaluating the right side expressions.

Hence the value is 1 for y and z while x gets 2.

Now, interchange position of ++x with ++y.

This time y will be 2.
 
Top Bottom