Chapter 4. Performing Logical Operations
In This Chapter
Using sometimes-illogical logical operators
Defining logical variables
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 bitwise operator. People don't use the bitwise operator in their daily business at all; it's unique to the computer world. We'll start with the simple and sneak up on the bitwise in this chapter.
Why Mess with Logical Operations?
C++ programs have to make decisions. A program that can't make decisions is of limited ...