In This Chapter
Defining mathematical operators in C++
Using the C++ mathematical operators
Increasing clarity with special mathematical operators
C++ offers all the common arithmetic operations: C++ programs can multiply, add, divide, and so forth. Programs have to be able to perform these operations to get anything done. What good is a health insurance program if it can’t calculate how much you’re supposed to (over) pay?
C++ operations look like the arithmetic operations you would perform on a piece of paper, except you have to declare any variables before you can use them (as detailed in Chapter 2):
int var1;int var2 = 1;var1 = 2 * var2;
This code snippet declares two variables, var1 and var2. It initializes var2 to 1 and then stores the results of multiplying 2 times the value of var2 into var1.
This chapter describes the complete set of C++ mathematical operators.
A binary operator is one that has two arguments. If you can say var1 op var2, op must be a binary operator. ...