The Logical OR Operator: ||
In English, the word or can indicate when one or both of two conditions satisfy a requirement. For example, you can go to the MegaMicro company picnic if you or your spouse work for MegaMicro, Inc. The C++ equivalent is the logical OR operator, written ||. This operator combines two expressions into one. If either or both of the original expressions is true, or nonzero, the resulting expression has the value true. Otherwise, the expression has the value false. Here are some examples:
5 == 5 || 5 == 9 // true because first expression is true5 > 3 || 5 > 10 // true because first expression is true5 > 8 || 5 < 10 // true because second expression is true5 < 8 || 5 > 2 // true because both expressions are true ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access