Unary Operators

A unary operator is an operator that performs an action on a single operand. You’ve already seen a unary operator in the not operator. Another example of a unary operator is an increment. The operand of an increment is a number, and the increment operator increases the value of the number by one (see Listing 7.4). The increment operator is how the programming language C++ got its name (C++ is like C, but 1 better).

Listing 7.4 Using the increment Operator

> num = 2;  2> num++;  // same as num = num + 1;  3> num;  3> num--;  // You can decrement, too.  2

Get Learning to Program 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.