0
Why makes it no difference between using "x++" or "++x" as increment in a for loop?
2 Answers
+ 1
They are very different. While x++ returns the value of the variable x and then increments x by 1, ++x will increment variable x by 1 and then return the new value (ie. return x + 1).
int x = 0;
printf("x++ is %d, ++x is %d", x++, ++x);
Output:
x++ is 0, ++x is 1
0
because inside the for loop that statement is final, no matter if its post-fix or pre-fix by the end of the statement, it increments regardless.