A relational operator is used to compare two values and the result of such as operation is always logical i.e either true or false. The valid relational operators supported by c++ are given
A logical operator is used to connect two relational expressions or logical expressions. The result of such an operation is always logical i.e either true or false. The valid logical operators supported by c++ are
Rules of logical operators
- The output of a logical AND operator is true if both operands are true. For all other combinations, the result is false
- The output of logical OR operation is false if both of its operands are false. For all other combinations, the result is true.
- The logical NOT is a unary operator. It negates the value of the operands.
( x < 6) && ( y > 6)
The operand x < 6 is true and the operand y > 6 is also true. Thus the result of the above given logical operation is also true. However, the result of the following expression is false because one of its operands is false:
(x<6) && (y > 7)
similarly consider the following expression:
(x<6) || (y > 7)
The operand x < 6 is true whereas the operand y>7 is false. Since these operands are connected by logical OR the result of these expressions is true
0 Comments