Operators and Shortcuts

So far, you have met only the basic operators for addition, multiplication, and assignment. C++ has a very rich set of operators, including several designed to manipulate the individual bits of numbers directly and efficiently. I won't do those immediately, but concentrate on the most commonly used operators first. C++ came from C, which was designed by people who hated unnecessary typing, so you may find the operator symbols cryptic at first. But everyone gets used to them with practice.

Division and Remainder

In C++, division is expressed by the forward slash (/). The operator / has the same precedence as the operator *, just as in ordinary arithmetic, so the parentheses are necessary in the following example:

;> 

Get C++ By Example: UnderC Learning Edition 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.