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(1) or false(0).
Symbol |
Operator |
Description |
Syntax |
&& |
Logical
AND |
Returns
true if both the operands are true. |
a
&& b |
|| |
Logical
OR |
Returns
true if both or any of the operand is true. |
a ||
b |
! |
Logical
NOT |
Returns
true if the operand is false. |
!a |
SIMPLE C PROGRAMMING USING LOGICAL OPERATORS
// 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
0 Comments
Post a Comment