O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

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

Logical Operators

Often you want to ask more than one relational question at a time. “Is it true that x is greater than y, and also true that y is greater than z?” A program might need to determine that both of these conditions are true, or that some other condition is true, in order to take an action.

Imagine a sophisticated alarm system that has this logic: “If the door alarm sounds AND it is after six p.m. AND it is NOT a holiday, OR if it is a weekend, then call the police.” The three logical operators of C++ are used to make this kind of evaluation. These operators are listed in Table 4.2.

Table 4.2. The Logical Operators
Operator Symbol Example
AND && expression1 && expression2
OR || expression1 || expression2
NOT ! !expression

Logical ...

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