C++ Logical (&&, ||, !) Operator Overloading
Logical operators are used for combining two or more conditions or constraints or to complement the evaluation of the original condition in consideration. The result returns a Boolean value, i.e., true or false. In C++, there are 3 logical operators:
- Logical AND (&&): This operator returns true only if all the operands are true or non-zero.
- Logical OR ( || ): This operator returns true if either of the operands is true or non-zero.
- Logical NOT ( ! ): This operator returns true if the operand is false or zero and vice-versa.
To use a logical operator on user-defined data type operator overloading is needed. Redefining the meaning of operators really does not change their original meaning, instead, they have been given additional meaning along with their existing ones.
a1 value is non-zero a2 value is zero
Example 2: Overloading AND (&&) Logical Operator
Both value is non zero
Example 3: Overloading OR (||) Operator
Any one or both value is non zero
My Personal Notes arrow_drop_up
Please Login to comment...