Logical operators
Before going any further, let's learn about a few logical operators. There are only three types of logical operators in C. They are, AND
, OR,
and NOT.
All three operators cover any logical operation. These operators help to remove complexities and shorten the code. Let's learn their symbols first:
Name |
Symbol |
Meaning |
|
|
This means, if all the conditions are true, then the condition is true. |
|
|
This means, if any of the conditions are true, then the condition is true. |
|
|
This operator reverses the condition. |
Now we will learn about the operators in detail.
AND operator
The AND
operator means if all the conditions fulfill the condition, the condition is true.
Let's look at an example.
Suppose, if today is Monday and the weather is good, I will go to school. See, if both conditions is true, I will do something. But if any of the conditions are false, I won't go to school. In this case, we can either use a nested if or a logical operator...