index++
adds 1 to the value of index and assigns it to index while evaluating to the value before adding 1. It is similar to index = index + 1;
There is a difference in that if you set index to 3 say; index = 3;
and then assign it to x like this x = index++
The value of x is 3 and the value of index is 4.
On the other hand ++index
adds one to index and evaluates to the new value. So index = 3;
and then assign it to x like this x = ++index
The value of x is 4 and the value of index is also 4.
So be careful how you use x++
as an expression. It may not do what you think, ++x
does what you think.
index--
is the same except subtract 1.