Logical Operators
Followings are all the logical Operators supported by C language.
i. Logical AND
&&
Checks if both the operands are non-zero and returns 1 if true else return 0.
Consider A = 20 and B = 10 (A&&B) would results 1
ii. Logical OR
||
Checks if any of the operands is non-zero and return 1 if true else return 0.
Consider A = 20 and B = 10 (A||B) would results 1
iii. Logical NOT
!
It will reverse the logic of operands and then check if it is true. And returns 1 if true else return 0.
Consider A = 20 and B = 10 !(A&&B) would results 0
Program example of logical operators
//An example of logical operators
#include<stdio.h>
int main()
{
int A=20, B=10;
printf("Consider A = 20 and B = 10\n");
printf("Logical AND (A&&B) = %d \n",(A&&B));
printf("Logical OR (A||B) = %d \n",(A||B));
printf("Logical NOT !(A&&B) = %d \n",!(A&&B));
return 0;
}
Output
Consider A = 20 and B = 10
Logical AND (A&&B) = 1
Logical OR (A||B) = 1
Logical NOT !(A&&B) = 0