Increment and Decrement

The most common value to add (or subtract) and then reassign into a variable is 1. In C++, increasing a value by 1 is called incrementing, and decreasing by 1 is called decrementing. There are special operators to perform these actions.

The increment operator (++) increases the value of the variable by 1, and the decrement operator (--) decreases it by 1. Thus, if you have a variable, C, and you want to increment it, you would use this statement:
C++; // Start with C and increment it.
This statement is equivalent to the more verbose statement
C = C + 1;
which you learned is also equivalent to the moderately verbose statement
C += 1;

Post a Comment