Logical Operators in C

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

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

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

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

Let us see the truth tables behind the logical operators in this Programming to understand Operators better.

&& AND Logical Operator in C

Condition 1Condition 2Condition 1 && Condition 2

|| (OR Operator) Truth Table

Condition 1Condition 2Condition 1 || Condition 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.