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 will do the trick for you. The table below shows the list of Logical Operators in C programming language with examples.
| OPERATORS | NAME | DESCRIPTION | EXAMPLE |
|---|---|---|---|
| && | AND | It returns true when both conditions are true | If (age > 18 && age <=35) |
| || | OR | It returns true when at least one of the conditions is true | If (age > 35 || age < 60) |
| ! | NOT | If the condition is true, the logical NOT operator makes it false | If age = 18 then !( age = 18) returns false. |
Let us see the truth tables behind the logical operators in this language to understand Operators better. For more, please refer to the All Operators and Relational articles in C Programming.
&& AND Logical Operator in this C Programming language.
| Condition 1 | Condition 2 | Condition 1 && Condition 2 |
|---|---|---|
| True | True | True |
| True | False | False |
| False | True | False |
| False | False | False |
|| (OR Operator) Truth Table
| Condition 1 | Condition 2 | Condition 1 || Condition 2 |
|---|---|---|
| True | True | True |
| True | False | True |
| False | True | True |
| False | False | False |