Is there a difference in ++i
and i++
in a for
loop? Is it simply a syntax thing?
There is no actual difference in both cases 'i
' will be incremented by 1.
But there is a difference when you use it in an expression, for example:
int i = 1;
int a = ++i;
// i is incremented by one and then assigned to a.
// Both i and a are now 2.
int b = i++;
// i is assigned to b and then incremented by one.
// b is now 2, and i is now 3