DIGIT-ARC read-only archive · snapshot: July 23, 2026

I got stuck in some coding.

2 posts · originally from https://geek.digit.in/community/threads/i-got-stuck-in-some-coding.162943/

R
Rakesh @_@ Original post #1
Sep 7, 2012 at 9:32 AM
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
Faun #2
Sep 7, 2012 at 10:48 AM
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.