Chapter 5: Loops and Files
5.1 The Increment and Decrement Operators
++ is the increment operator.
It adds one to a variable.
val++; is the same as val = val + 1
++ can be used before [prefix] or after [postfix] a variable:
++val; val++;
-- is the decrement operator.
It subtracts one from a variable.
val--; is the same as val = val - 1
-- can be also used before [prefix] or after [postfix] a variable:
--val; val--;
Increment and Decrement Operators in Program 5-1
// This program demonstrates the ++ and -- operators.
#include
using namespace std;
int main[]
{
int num = 4; // num starts out with 4.
// Display the value in num.
cout number]
{
cout