Google News
logo
Logical Operators In C Language
Logical Operators are used when we want to test more than one condition and make decisions. Here the operands can be constants, variables and expressions.
There are 3 logical operators in c language they are   &&, ||, !
Operator Meaning of Operator Example Description
&& Logical AND If c=5 and d=2 then,((c==5) && (d>1)) returns true. It returns true when both conditions are true
|| Logical OR If c=5 and d=2 then, ((c==5) || (d>5)) returns true. It returns true when atleast one of the condition is true
! Logical NOT If c=5 then, ! (c==5) returns false If condition is true it returns false
  Program : A program to illustrate the use of Logical Operators
#include<stdio.h>
#include<conio.h>
void main ( )    
  {         
	printf(“\n In  5>3 && 5<10  : %3d”,  5>3&&5<10);
	printf(“ \n In  8<5 || 5= =5  : % 3d”, 8<5 || 5= =5);
	printf(“\n In  !(8 = =8)  : %3d”, !(8= =8)) ;  
   }

Output :

In 5>3 && 5<10 : 1
In 8<5 || 5= =5 : 1
In !(8 = =8) : 0