Logical Operators

Logical operators or Boolean operators in C are the operators which are used for combining purpose of two or more than two expressions. These operators also returns 1 for TRUE and 0 for FALSE as similar to relational operator. Following table represents the list of logical operator in C.-1

All the operators listed above are binary operator except logical not operator. Logical NOT operator is a unary operator as it takes only one operand to perform logical operation on its operand whereas logical OR and Logical AND operator takes two operands.These operators are mostly used conditional statements.

Now one by one I am going to make you understand about these operators.

Logical AND Operator:

Untitled-2

After going through above table you might have came to know how this operator works.This operator returns the value 1(TRUE) if and only if the both conditions are true otherwise it will return 0 (FALSE). In this operator if the first condition is true then only the compiler will check for the second condition and then it will return the value of whole expression otherwise if first condition is false, simply it will return 0.It will not check the second condition.

for example:

take two variable num1 and num2 having value 60 and 70

In the above example both the conditions are true hence the result of the whole expression will be 1 and it will print “condition satisfied” .

In the above example first condition is false hence this expression will return result 0 and it will print “condition not satisfied” as result..

Logical OR Operator:

Untitled-3

This operator returns the value of expression 1 (TRUE) if any one of the condition is true that means logical OR operators returns 0 only when both the condition is false.

Let us consider the above example once again with the OR Operator.

In this example the first condition of the expression is TRUE hence it will return 1 as the value of whole expression and it will print “condition is satisfied“.

In this example both conditions are FALSE hence it will return 0 as the value of whole expression and  print “condition not satisfied“.

Logical NOT Operator:

Untitled-1

This operator works on one operand and convert the value of expression. If  the value of expression is 1 it will return 0 and if the value of expression is 0 it will return 1.

 

 

Leave a Reply