| In this blog |
|---|
| logical operators |
logical operators
| operator | meaning |
| && | logical and |
| || | logical or |
| ! | logical not |
logical and (&&)
| A | B | A&&b |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
if both the operand are true only then A&&b would be 1
eg
printf("%d", A&&B) // A=2 ,B=3 output would be 1
(note: if the left operand is false in this case A then it would not check for the right operand if it is true or not ,B in this case )
logical or ( || )
| A | B | A||b |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
if one of the operand is true then the result of A || b would be true
eg
printf("%d", A||B)// A=2 ,B=0 output would be 1
(note: if the left operand is true in this case A then it would not check for the right operand if it is true or not ,B in this case )
logical not ( ! )
| A | !A |
| 0 | 1 |
| 1 | 0 |
logical not reverse the output , if it is true then it is reverse to false or vice versa.
eg
printf("%d", !A) // A=1 output would be 0



No comments:
Post a Comment