Example of Logical Operators in C
Logical Operators
An operator used to perform Boolean logic upon two Boolean expressions is called Logical operator. Logical operators return Boolean results (true or false) and take Boolean values as operands.
Note: ! has lowest priority, while && has highest.
The logical operators && and || are used when we want to test more than one condition and make decisions. An Example is
A Logical expression as shown above yields a value of one or zero according to the truth table shown below.
If a =20, b=10 and c=10 than previous logical results in True as 1&& 1 yields 1 following above truth table for AND.
An operator used to perform Boolean logic upon two Boolean expressions is called Logical operator. Logical operators return Boolean results (true or false) and take Boolean values as operands.
C has three logical operators. &&(AND), ||(OR), !(NOT) |
Note: ! has lowest priority, while && has highest.
The logical operators && and || are used when we want to test more than one condition and make decisions. An Example is
a > b && c = =10
A Logical expression as shown above yields a value of one or zero according to the truth table shown below.
Truth Table |