What I'm about to say is a helpful way of thinking about it. It may not be completely exactly true in all cases :)
When you do ++ or -- you don't just change the value; you also get the value back, for using with something else.
If you aren't actually using it for anything else, like this:
i++;
or this
++i;
then it doesn't matter.
But what if you're doing this:
1 2 3
|
int i = 4;
int x;
x = i++;
|
?
In this case, you get the value of i back to be used before it's changed; in effect, the compiler sets the value of x to equal i (which is 4), and then changes the value of i, so at the end, x = 4 and i = 5.
This:
1 2 3
|
int i = 4;
int x;
x = ++i;
|
changes the value of i before it is used, so at the end of this, x = 5 and i =5.