Chapter 4

Performing Logical Operations

In This Chapter

arrow Using sometimes-illogical logical operators

arrow Defining logical variables

arrow Operating with bitwise logical operators logically, a bit at a time

The most common statement in C++ is the expression. Most expressions involve the arithmetic operators, such as addition (+), subtraction (–) and multiplication (*), as demonstrated in Chapter 3.

This chapter describes a whole other class of operators known as the logical operators. In comparison with the arithmetic operators, most people don’t think nearly as much about this type of operation. It isn’t that people don’t deal with logical operations such as AND and OR — we compute them constantly. I won’t eat cereal unless the bowl contains cereal AND the bowl has milk in it AND the cereal is coated with sugar (lots of sugar). I’ll have a Scotch IF it’s single-malt AND someone else is paying for it. People use such logical operations all the time, but they don’t write them down as machine instructions (or think of them in that light).

Logical operators fall into two types. The AND and OR operators are what I will call simple logical operators. The second type of logical operator is the ...

Get C++ For Dummies, 7th 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.