
Larry C. answered 05/04/19
Computer Science and Mathematics professional
i++ is called post-increment and ++i is pre-increment. There is no difference as far as the final value of i is concerned, but there is a major difference in other parts of the statement that may use i. Consider this code snippet:
i = 10;
j = i++;
k = ++i;
With post-increment, the value of the variable is evaluated before the increment happens. So, in the second statement, i is evaluated as 10 and j gets that value, THEN i is incremented to 11.
In the third statement, pre-incrementing means the variable is incremented before the value is evaluated. So i is incremented to 12 and then k gets the new value of 12 instead of the old value of 11.