Manipulating variables
At this point we know exactly what variables are, the main types, and how to declare and initialize them, but we still can't do that much with them. We need to manipulate our variables, add them, take them away, multiply, divide, and test them.
First we will deal with how we can manipulate them and later we will look at how and why we test them.
C++ arithmetic and assignment operators
In order to manipulate variables, C++ has a range of arithmetic operators and assignment operators. Fortunately, most arithmetic and assignment operators are quite intuitive to use, and those that aren't are quite easy to explain. To get us started, let's look at a table of arithmetic operators followed by a table of assignment operators that we will regularly use throughout this book:
Arithmetic operator |
Explanation |
|
The addition operator can be used to add together the values of two variables or values. |
|
The subtraction operator can be used to take away the... |