< previous page page_65 next page >

Page 65
+
Unary plus
-
Unary minus
+
Addition
-
Subtraction
*
Multiplication
/
0065-01.gif
%
Modulus (remainder from integer division)

The first two operators are unary operatorsthey take just one operand. The remaining five are binary operators, taking two operands. Unary plus and minus are used as follows:
-54   +259.65   -rate
You almost never use the unary plus. Without any sign, a numeric constant is assumed to be positive anyway.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Unary Operator An operator that has just one operand.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Binary Operator An operator that has two operands.
You may not be familiar with integer division and modulus (%). Let's look at them more closely. Note that % is used only with integers. When you divide one integer by another, you get an integer quotient and a remainder. Integer division gives only the integer quotient, and % gives only the remainder. (If either operand is negative, the result may vary from one C++ compiler to another.)
0065-03.gif
In contrast, floating point division yields a floating point result. The expression
7.0 / 2.0
yields the value 3.5.
Here are some expressions using arithmetic operators and their values:

 
< previous page page_65 next page >