The Logical AND Operator: &&
The logical AND operator, written &&
, also combines two expressions into one. The resulting expression has the value true
only if both of the original expressions are true
. Here are some examples:
5 == 5 && 4 == 4 // true because both expressions are true5 == 3 && 4 == 4 // false because first expression is false5 > 3 && 5 > 10 // false because second expression is false5 > 8 && 5 < 10 // false because first expression is false5 < 8 && 5 > 2 // true because both expressions are true5 > 8 && 5 < 2 // false because both expressions are false
Because the &&
has a lower precedence than the relational operators, you don’t need to use parentheses in these expressions. Like the ||
operator, the &&
operator ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.