O'Reilly logo

C++ For Dummies, 7th Edition by Stephen R. Davis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required