posted 6 years ago
Let me try.
Think only about one operation at a time:
x++ place to expression, then increment
++x increment, then place to expression
First line
1. x = 3
Second line
x++ means, place value to the expression, then increment. Your x = 3 from the first line.
2. y = 3 + (++x) + (x++)
Remember, you placed 3 to the expression, but haven't incremented yet, so your x after increment becomes 4. And beside that you have next operation ++x, which means, increment first, then place to expression. So x = 4 + 1.
3. y = 3 + 5 + (x++)
So, next operation you have x++, which means again, place x value to the expression, and only then increment. Your x is 5.
4. y = 3 + 5 + 5
5. y = 13
Technically you still need to increment x after you placed it to the expression, but it doesn't make any difference in your case anymore because sum has been assigned to y already. If you were to use x later on in further calculations, your x would be 6 now.
Hope it is clear now.