Boolean with Logical Operators in C language
Categories: C language
The Boolean type value is associated with logical operators. There are three types of logical operators in the C language:
&&(AND Operator): It is a logical operator that takes two operands. If the value of both the operands are true, then this operator returns true otherwise false
||(OR Operator): It is a logical operator that takes two operands. If the value of both the operands is false, then it returns false otherwise true.
!(NOT Operator): It is a NOT operator that takes one operand. If the value of the operand is false, then it returns true, and if the value of the operand is true, then it returns false.
#include <stdio.h>
#include<stdbool.h>
int main()
{
bool x=false;
bool y=true;
printf("The value of x&&y is %d", x&&y);
printf("\nThe value of x||y is %d", x||y);
printf("\nThe value of !x is %d", !x);
}
Output
The value of x&&y is 0
The value of x||y is 1
The value of !x is 1