August 2001
Beginner
482 pages
10h 52m
English
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.
| Operator | Symbol | Example |
|---|---|---|
| AND | && | expression1 && expression2 |
| OR | || | expression1 || expression2 |
| NOT | ! | !expression |
Read now
Unlock full access