Search code examples
cdecrementpostfix-operatorequality-operator

How do you evaluate z = x- - == y + 1;


given that

int w = 1;
int x = 6;
int y = 5;
int z = 0;
 
z = !z || !x && !y;
printf("%d\n", z);

z = x-- == y + 1;
printf("%d\n", z);

Could someone explain how the line below would evaluate to 1 if x-- is 5 and y+1 is 6?

z = x-- == y + 1;

Solution

  • The expression x-- evaluated to the value of x before being decremented.

    So x-- == y + 1 is the same as 6 == 5 + 1 which is true, then the value 1 is assigned to z.