7.11 Conditional logical operators
Visual Studio .NET 2003
The && and || operators are called the conditional logical operators. They are also called the "short-circuiting" logical operators.
- conditional-and-expression:
- inclusive-or-expression
conditional-and-expression && inclusive-or-expression - conditional-or-expression:
- conditional-and-expression
conditional-or-expression || conditional-and-expression
The && and || operators are conditional versions of the & and | operators:
- The operation
x&&ycorresponds to the operationx&y, except thatyis evaluated only ifxistrue. - The operation
x||ycorresponds to the operationx|y, except thatyis evaluated only ifxisfalse.
An operation of the form x && y or x || y is processed by applying overload resolution (Section 7.2.4) as if the operation was written x & y or x | y. Then,
- If overload resolution fails to find a single best operator, or if overload resolution selects one of the predefined integer logical operators, a compile-time error occurs.
- Otherwise, if the selected operator is one of the predefined Boolean logical operators (Section 7.10.2), the operation is processed as described in Section 7.11.1.
- Otherwise, the selected operator is a user-defined operator, and the operation is processed as described in Section 7.11.2.
It is not possible to directly overload the conditional logical operators. However, because the conditional logical operators are evaluated in terms of the regular logical operators, overloads of the regular logical operators are, with certain restrictions, also considered overloads of the conditional logical operators. This is described further in Section 7.11.2.