EQUALITY AND LOGICAL OPERATORS
#100DaysOfCodeChallenge

Operators in C language plays a decisive role in determining the operation that needs to be performed. Basically, an operator is a symbol used in C program that specifies the mathematical, relational and logical operations that is to be carried out on an operand. An operand can be variable or a constant on which an operator works and together forms an expression. The operators on the whole is divided into 10 different categories.
Let us now look in for Equality and Logical Operators.
EQUALITY OPERATORS :
This type of equality operators include only the the equal to operation and not equal to operation.
>>"Equal to" operator is denoted by the symbol ==
>>"Not equal to" operator is denoted by the symbol !=
>>Basically the primary job of these equality operators is to compare the operands and the conditions placed.
>>The "equal to" operator returns the value 1 if the operands are equal and value 0 if it is false.
>>On the contrary, the "not equal to" operator returns 1 if the operands are not equal and 0 if the operands are equal.
SYNTAX :
operand == operand
operand != operand
EXAMPLE :
Let us consider two variables a and b and check with equality operators.
>>Let a=20 and b=10 in the first case,
a == b ………………..returns the answer as 0 (since the values are not same)
a != b………………….returns the answer as 1 (since the values are not same)
>>Let a=30 and b=30 in the second case,
a == b………………….returns the answer as 1 (since the values are same)
a != b……………………returns the answer as 0 (since the values are same)
LOGICAL OPERATORS :
In a C language, there are three Logical operators present. They are as follows,
1. Logical AND
2. Logical OR
3. Logical NOT
Firstly let us look in for Logical AND.
LOGICAL AND :
>>AND is represented by the symbol &&.
>>SYNTAX :
condition && condition
>>This operator will return true only if all the conditions are satisfied, else it returns false.
>>EXAMPLE:
For better understanding, let us take the following example into consideration.
(a>b) && (a>c)
The above condition will return true only if both the conditions are true. If one of the condition is found to be false, it is terminated and false is printed as the answer. For example, if a is not greater than b, then it will directly print the output and it will not check the second condition. That is, if the first condition itself is ascertained to be false, then the second condition is not at all checked, directly the output is printed as false.
Truth table for AND :
A …………………..B…………………A && B
0……………………0…………………….0
0……………………1…………………….0
1……………………0…………………….0
1……………………1…………………….1
LOGICAL OR :
>>OR is represented by the symbol ||.
>>SYNTAX :
condition || condition
>>This operator will return true even if one of the conditions are satisfied, and returns false only when all the conditions fail to satisfy.
>>EXAMPLE:
For better understanding, let us take the following example into consideration.
(a>b) || (a>c)
The above condition will return false only if both the conditions are not satisfied. If one of the condition is found to be true, it is terminated and true is printed as the answer. For example, if a is greater than b, then it will directly print the output and it will not check the second condition. That is, if the first condition itself is ascertained to be true, then the second condition is not at all checked, directly the output is printed as true.
Truth table for OR :
A …………………..B…………………A || B
0……………………0…………………….0
0……………………1…………………….1
1……………………0…………………….1
1……………………1…………………….1
LOGICAL NOT :
>> NOT is represented by the symbol !
>>SYNTAX :
! operand
>>This operator just reverses the expression.
>> This operator is known to take a single expression and reverses the value of the expression being used.
>>For example, if the expression has zero, then NOT will produce 1 and if the expression has 1, then NOT is ascertained to produce 0.
Truth table for OR :
A ………………….. ! B
0……………………..1
1……………………..0
Thank you!!
About the Creator
Preethi Siva
Writing is not my hobby.........
It comes when my heart is connected to my soul and says to write!!!



Comments
There are no comments for this story
Be the first to respond and start the conversation.