a++ will return a and increment it, ++a will increment a and return it:
a = 5;
b = a++; // b = 5, a = 6
a = 5;
b = ++a; // b = 6, a = 6
Every expression in C or C++ has a type, a value, and possible side-effects.
int i;
++i;
The type of ++i
is int
. The side-effect is to increment i
. The value of the expression is the new value of i
.
int i;
i++;
The type of i++
is int
. The side-effect is to increment i
. The value of the expression is the old value of i
.
it's the preincrement operator
nice explanation here