#include<stdio.h>
int main ()
{
int i = 5;
printf("%d\n", i = ++i == 6);
return 0;
}
// What's the output ? [Do not execute / run]
// Source : http://www.youngprogrammer.com/

I know the answer is 1 but what is the logic behind this,please let me know

C expression always executes from right to left.
lets analyze, printf(“%d\n”, i = ++i == 6);
++i == 6, will execute first.
this is a condition which checks, whether ++i is equals to 6
it is true. becoz, i = 5 and its pre-incremented, i.e value of ‘i’ increases before checking the condition
so, ++i == 6 returns true. integer value of true = 1
integer value of false = 0
that is, left most ‘i’ is initialized to 1

Should I answer it?

I know the answer is 1 but what is the logic behind this,please let me know

C expression always executes from right to left.

lets analyze, printf(“%d\n”, i = ++i == 6);

++i == 6, will execute first.

this is a condition which checks, whether ++i is equals to 6

it is true. becoz, i = 5 and its pre-incremented, i.e value of ‘i’ increases before checking the condition

so, ++i == 6 returns true. integer value of true = 1

integer value of false = 0

that is, left most ‘i’ is initialized to 1

Correct Output : 1

Thanks a lot!!!!

1