int main()
{
int a = 1, b = 1, c = 1;
int x = a + a++ ;
int y = 1 + b++ ;
int z = c++ + c++ ;
printf("%d\n %d\n %d\n", x, y, z);
}
Output:
3
2
3
I know there are similar questions out there but nothing addressed my issue. I'm basically doing the same thing in 2nd & 3rd lines of the main function . Why do I receive different outputs?
And all the materials I referred to so far said that post increments take place after the operations have taken place. In that case, shouldn't we assign z
to c+c(i.e 1+1=2) and then increment the value of c
?But clearly my logic is wrong. Can someone explain that too?