Increment and Decrement
++x and x++ used to increment x (equivalent to
x = x + 1)
--x and x-- used to decrement x (equivalent to x = x - 1)
- ++x is pre-increment. The increment is done before x is used in the rest of the expression.
- x++ is post-increment. The increment is done after x is used in the rest of the expression.
Note: This only matters if the variable is actually used in another expression. These two statements by themselves have the exact same effect:
x++; // increment x ++x; // increment xExamples of pre-increment and post-increment
int a = 5, b = 3; int c = b * ++a; // After this statement, c is 18, a is 6 int x = 6, y = 4; int d = x - y++; // After this statement, d is 2, y is 5