Conditional and Logical Operators
When handling boolean values, you want to be able to test for a value, but also to modify it. This is what conditional and logical operators are for.
The three main operators acting on boolean values are shown in Listing 9.10:
► &&—AND, returns true only if both operands are true.
► ||—OR, returns true if at least one of the operands is true.
► !—NOT, returns true if the single operand is false, and returns false if it is true.
LISTING 9.10 Conditional and Logical Operators bool valuel = true;
bool value2 = !value1; // stores false into value2
bool value3 = valuel && value2; // stores false into value3 bool value4 = valuel || value2; // stores true into value4
Post a comment