x--
will decrement value of x
by 1. It is a postfix decrement operator, --x
is a prefix decrement operator.
So, what’s going on here?
int x, y; //initialize x and y
x = 7; //set x to value 7
x--; //x is decremented by 1, so it becomes 6
y = x * 2; //y becomes 6*2, therefore y becomes 12
x = 3; //x becomes 3
By analogy, the ++
will increase a value by 1. It also has a prefix and postfix variant.