int i = 5;
int j = 5;
std::cout << i + j++ << '\n';
Output:
10
1 2 3 4
int i = 5;
int j = 5;
std::cout << i + ++j << '\n';
Output:
11
The first one will add i and j together, and then increment j; whereas the second one will increment j before the addition takes place.
EDIT:
I also think that someone on here once told me that ++i was more efficient. I've used it since then.
But which ever way it's used, you have to think about the outcome. As in the above code.
> someone on here once told me that ++i was more efficient.
> I've used it since then.
It is a good habit to get into - never use the prefix version of the increment or decrement operators unless the value before the increment/decrement is needed. For user defined types, ++iterator could very well be more efficient than iterator++. For any type, ++i would not be less efficient than i++.