Saturday 5 January 2013

Logical operators ( !, &&, || )

The Operator !is the C++ operator to perform the Boolean operation NOT, it has only one operand, located at its
right, and the only thing that it does is to inverse the value of it, producing false if its operand is true and true if its
operand is false. Basically, it returns the opposite Boolean value of evaluating its operand. For example: 




The logical operators &&and ||are used when evaluating two expressions to obtain a single relational result. The
operator &&corresponds with Boolean logical operation AND. This operation results true if both its two operands
are true, and false otherwise. The following panel shows the result of operator &&evaluating the expression a &&
b:
&& OPERATOR




The operator ||corresponds with Boolean logical operation OR. This operation results true if either one of its two
operands is true, thus being false only when both operands are false themselves. Here are the possible results of a
|| b: 



|| OPERATOR



For example:

No comments:

Post a Comment