O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required