Logical operator:C Programming Language - Part 2.3
Logical operator
Relational and Logical Operators are:
Relational Operators
Equality Operator
Logical Operator
There are four types of Relational Operators in the C programming language:
Operator Meaning
<Less then
<= Less then or equal to
> Greater then
> = Greater then or equal to
I think x, y are two variables. The value of x is 5, the value of y is 6. When x is seen by y, y is smaller than y is. Since x is smaller than x, x <y expression is true and its value is 1. Again x> y expression is false and its value is 0. The reason is not bigger than x y
Using Relational Operator, we can easily extract what is small in two numbers. Which we will see in the next section if-else section.
Equality Operator:
There are two Equality Operators related to Relational Operators. They were given below
Operator Meaning
== Equal to
! = Not Equal to
The first one here is two equal signs. Both matches the Equal to Operator. The second one is a! (Pronunciation knot) and publishes Not Equal to Operator with an equal sign.
For example, thinks x, y are two variables X value 5 The value of y is 6. So x == y means the value of x and y are equal. But the value of our x and y is not equal. So x == y expression is false and its value is 0. Again if x! = Y (pronunciation x is not equal to y) then expression is true and its value will be.
It should be remembered that assignment operator = and equality operator == are completely different. Assignment operator is used to assign a value to a variable. And the Equality Operator (==) is used to see if the two expressions are equal. There will not be any place at one place here. Then there will be a huge error in the program. Many people first make this mistake.
Logical Operator:
C programming consists of two logical operators. They were given below
Operator Meaning
&& And
|| Or
&& is called logical and and || Who is called Logical Or
&& (Read and Operator):
Suppose x, y, z are three variables. Now (x <y) && (y <z) is an expression. Now its value will be true if (x <y) and (y <z) are true. If any one of the (x <y) and (y <z) is false then the value (x <y) && (y <z) is false.
|| (Read Or Operator):
Suppose x, y, z are three variables. Now (x <y) || (y <z) is an expression. Now its value will be true if (x <y) and (y <z) are true. Or any of the (x <y) and (y <z) is true. If the two (x <y) and (y <z) lie together at all (x <y) || (y <z) the value of these will lie.
Below are some examples of Relational and Logical Operators:
Suppose x, y, z are three variables. The value of x is 5, the value of y is 6 and z is 7.
Expression explanation value
X <y True 1
X == 5 True 1
Y == 4 False 0
(X + y)> z True 1
(X + y) <= z False 0
X! = Y True 1
(X <y) && (y == 6) True 1
(X <y) && (z! = Y) True 1
(X> y) || (z! = Y) True 1
(X> y) && (z! = Y) False 0
(X <y) && (z == y) False 0
(X <y) || (z == y) True 1
That is, all true values are 1 and false is 0.
No comments