Possible Duplicate:
Difference between i++ and ++i in a loop?
Is there a difference between i++ and ++i ?
Possible Duplicate:
Difference between i++ and ++i in a loop?
Is there a difference between i++ and ++i ?
i++ is postincrement and ++i is preincrement. The former allows you to use the value of i in an expression and then increments i at the end. The later increments i first and then allows you to use it. For example:
int prev_i=i++;
and
int next_i=++i;
i++ increments i after the statement. ++i increments i before the statement is evaluated.
Yes.
i++ is post-increment. It returns a copy of i and THEN increments the value of i.
++i is pre-increment. It increments i and THEN returns the value of i.
++c
is pre-increment, so you increment the value before you use it, and c++
is post-increment, so you use the value then increment it.
int c;
c = 5;
cout << c++; // prints 5, then sets the value to 6
c = 5;
cout << ++c // sets the value to 6, then prints 6
So this can have implications in loops, etc. i.e.
int i;
for (i=0; i < 2; i++) cout << i; // prints 0, then 1
for (i=0; i < 2; ++i) cout << i; // prints 1, then 2
There are also potential performance implications. See this post for more information.