LOGICAL OPERATORS IN C WITH EXAMPLE | . Meaning |
< | less than |
<= | less than or equal to |
> | greater than |
>= | greater than or equal to |
== | equal to |
!= | not equal to |
&& | logical AND |
|| | logical OR |
! | logical NOT |
The above 1st 6 are relational operators in java and last 3 are logical operators
The relation operators are used to compare 2 values. The output of relational operators is either true (1) or false (0)
Syntax:-
value1 relational_operator value2
Example:-
2 < 10 True
3 > 8 False
7.5>=5 True
value1 and value2 are can be constants, variable or combination of them.
Relation operator are used in if-else or in loop statement.
Example:-
Program to find Greatest number between 2
Logical operators:-
logical operators && and || are used to when we want to check 2 or more condition statement.
Example
8 > 7 && 5 < 8 True
8 < 5 || 8 < 9 False
7 > 2 && 19 < 2 False
AND (&&) operator output is true only when either condition statement is true.
OR (||) operator output is false only when either condition statement is false.
Truth table:-
A | B | AND |
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
A | B | OR |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
NOT (!) logical operator is used for compliment condition statement outputs.
Truth table:-
0 comments:
Post a Comment