Logical Operator in C
Logical Operators are used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a Boolean value either true or false.
S. No. | Symbol | Operator | Description | Syntax |
---|---|---|---|---|
1 | && | Logical AND | Returns true if both the operands are true. | a && b |
2 | || | Logical OR | Returns true if both or any of the operand is true. | a || b |
3 | ! | Logical NOT | Returns true if the operand is false. | !a |
Example of Logical Operators in C
// C program to illustrate the logical operators
#include <stdio.h>
int main()
{
int a = 25, b = 5;
// using operators and printing results
printf("a && b : %d\n", a && b);
printf("a || b : %d\n", a || b);
printf("!a: %d\n", !a);
return 0;
}
Output
a && b : 1 a || b : 1 !a: 0
Operators in C
In C language, operators are symbols that represent operations to be performed on one or more operands. They are the basic components of the C programming. In this article, we will learn about all the built-in operators in C with examples.