C++ Logical Operators

C++ Logical Operators


Define :
Logical operators are used to check either an expression is true or false. If the expression is true, it returns 1 otherwise if the expression is false, it returns 0.

Operator

Example

Operation

 

&&

expression1 &&expression2

Logical AND.

 True only if all the operands are true.

||

expression1 || expression2

Logical OR.
True if at least one of the operands is true.

!

expression1! expression2

Logical NOT.
True only if the operand is false.

Example:

Output :