Incrementing and Decrementing

Let's look in a little more detail at line 19 of Tape().

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.

The increment operator (++) increases the value of its variable by 1, and the decrement operator (--) decreases it by 1. Thus, if you had a variable, x, and you wanted to increment it, you would use this statement:

x++;  // Start with x and increment it.

Both the increment operator and the decrement operator come in two styles: prefix and postfix.

Prefix The operator is written ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.