You should notice that the expression evaluates from left to right:
The first x++ increments the value of x, but returns the previous value of 3.
Then ++x increments the value of x and returns a new value of 5 (after two increments).
x = x++ + ++x; 3 + 5 = 8
However, even if you change the expression to
x = ++x + x++;
you still get 8
x = ++x + x++ 4 + 4 = 8
This time, the second increment x ( x++ ) is overwritten as soon as the result of the addition is assigned to x.
source share