Logical Operators in C

The Logical operators in C are some of the Operators, which are used to combine two or more conditions. And perform the logical operations using && (Logical AND), || (Logical OR) and ! (Logical NOT)

The Relational Operators in C are used to compare two variables, what if we want to compare more than one condition? Very simple, C logical operators will do the trick for you.

The below table shows all the list of Logical Operators in C with examples.

OPERATORSNAMEDESCRIPTIONEXAMPLE
&&logical ANDIt returns true when both conditions are trueIf (age > 18 && age <=35)
||logical ORIt returns true when at-least one of the condition is trueIf (age > 35 || age < 60)
!logical NOTIf the condition is true, logical NOT operator makes it falseIf age = 18 then!( age = 18) returns false.

Let us see the truth tables behind the logical operators in C Programming for better understanding of Operators.

&& LOGICAL AND Operator

Condition 1Condition 2Condition 1 && Condition 2
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

|| (LOGICAL OR Operator)

Condition 1Condition 2Condition 1 || Condition 2
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse