Hi!
The first time I encountered this in
Java, I was also very surprised because, i=i++ in C (in my compiler) gives a value of 1 to i.
However, in Java what happens I think is this -->
saying i++ or ++i on its own has no problem. Both of them would increment i.
However, saying i++ as part of the expression is different. What happens is that i++ is evaluated giving a value of 0 (since it is post-increment), which for some some reason is stored in a temporary variable. Next, increment is performed, setting i to 1. And then lastly, the assignment is performed, fetching the value (that was saved) which was 0 and storing it in i. Thus final value is still 0. If i is not used in the left hand side, then it is not so confusing -->
int x = 0;
int i = 10;
x = i++; // makes x 10 and i 11
I hope this helps.