The Programming Gurus

Logical Operators In C


Logical operators in C:
  • These operators are used to perform logical operations on the given expressions.
  • There are 3 logical operators in C language. They are, logical AND (&&), logical OR (||) and logical NOT (!).
S.no Operators Name Example Description
1 && logical AND (x>5)&&(y<5) It returns true when both conditions are true
2 || logical OR (x>=10)||(y>=10) It returns true when at-least one of the condition is true
3 ! logical NOT !((x>5)&&(y<5)) It reverses the state of the operand “((x>5) && (y<5))” If “((x>5) && (y<5))” is true, logical NOT operator makes it false
Code:
#include <stdio.h>

int main()
 {
 int m=40,n=20;
 int o=20,p=30;
 if (m>n && m !=0)
 {
 printf("&& Operator : Both conditions are true\n");
 }
 if (o>p || p!=20)
 {
 printf("|| Operator : Only one condition is true\n");
 }
 if (!(m>n && m !=0))
 {
 printf("! Operator : Both conditions are true\n");
 }
 else
 {
 printf("! Operator : Both conditions are true. " \
 "But, status is inverted as false\n");
 }
 }
Output:
&& Operator : Both conditions are true
|| Operator : Only one condition is true
! Operator : Both conditions are true. But, status is inverted as false
0 Comments For "Logical Operators In C"

Back To Top