What happens (behind the curtains) when this is executed?
int x = 7;
x = x++;
That is, when a variable is post incremented and assigned to
What happens when int x = 7; x = x++;
?
ans -> x++
means first use value of x for expression and then increase it by 1.
This is what happens in your case. The value of x on RHS is copied to variable x on LHS and then value of x
is increased by 1.
Similarly ++x
means ->
increase the value of x first by one and then use in expression .
So in your case if you do x = ++x ; // where x = 7
you will get value of 8.
For more clarity try to find out how many printf statement will execute the following code
while(i++ <5)
printf("%d" , ++i); // This might clear your concept upto great extend