2.6 Arithmetic
Most programs perform arithmetic calculations. Figure 2.9 summarizes the arithmetic operators. Note the use of various special symbols not used in algebra. The asterisk (*
) indicates multiplication and the percent sign (%
) is the remainder operator, which we’ll discuss shortly. The arithmetic operators in Fig. 2.9 are all binary operators—they each take two operands. For example, the expression number1 + number2
contains the binary operator +
and the two operands number1
and number2
.
Fig. 2.9 Arithmetic operators.
Operation | Arithmetic operator | Algebraic expression | C++ expression |
---|---|---|---|
Addition | + |
f + 7 |
f + 7 |
Subtraction | - |
p – c |
p - c |
Multiplication | * |
bm or b · m |
b * m |
Division | / |
x / y or or x ÷ y |
x / y |
Remainder ... |
Get C++ How to Program, 10/e 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.