hot post

relational operators | Athematic instruction in c (part 6)

Logical Operators in C language || Arthematic instruction in c part(15)


Athematic instruction in c (part 15) || relational operators

Hello friends,

Today I will tell you relational operators in Athematic instruction in c programming. We have learnt bitwise operator in previous post and we have also completed unary operators and arithmetic operators in our previous post so, please read first my previous post then read this post. TO go on my previous post link is given below

(https://grapsvs.blogspot.com/2020/04/arithmetic-instruction-in-c-part-11.html)

(https://grapsvs.blogspot.com/2020/05/arithmetic-instruction-in-c-part-14.html)

(https://grapsvs.blogspot.com/2020/05/Arithmetic-instruction-in-c-programmingpart%2013.html)

In this post, I will tell you ‘what is relational operators?’

‘How many types of relational operators?’ and also see best examples through examples you can understand easily.

So, let’s start

What are relational operators

Relational operators are used to relate two variables or two conditions with each other, used to compare mean, hence it is also called comparison operator. This operator is used to check the relationship between two variables, constants or operands.

If we take an example of real life and explain to you about the relational operator, then you will be able to understand very easily. For example, if a company has vacancy for a post in any company and requires minimum 70% marks in Graduation for that, then here you will first compare 70% with your marks, which will be compared only by the relational operators. Like 78%> = 70%.

Hope you would understand the definition of relational operators

Rules of relational operators

Relational operators always yield result either 0 or 1.

Every non-zero value is true and zero is false

True is 1 and false is 0

 

All the relational operator is shown in the table below, which can be used in C programming.

 

operators

description

        <

Less than

         >

Greater than

       <=

Less than equal to

        >=

Greater than equal to

        ==

 Equal to

         !=

Not equal to

 

Now let’s study these operators one by one

[<] operator

What is ‘less then operator’?

This operator is called Less than operator. It is used to check the value of the first operand less than the value of the second operand. If the value of the first operand is smaller than the value of the second operand then it returns true such as (3 <4) return true

Example

#include<stdio.h>
#include<conio.h>
void main()
{

int =x;
clrscr();

x= 3<4
printf("%d",x);

getch();
}

 

Output

Output will be 1 because it is true that 3 is less then 4.

[>] operator

What is ‘greater then operator’?

This operator is called Greater than operator. It is used to check the value of the first operand greater than the value of the second operand. If the value of the first operand is greater than the value of the second operand then it returns true like (6> 3) return true

Example

#include<stdio.h>
#include<conio.h>
void main()
{

int =x;
clrscr();

x= 6<3
printf("%d",x);

getch();
}

 

Output

Output will be 1 because it is true that 6 is greater then 3.

[<=] operator

What is ‘Less than equal to operator’?

This operator is called Less than equal to operator. This is used to check the value of the first operand less than the value of the second operand. If the value of the first operand is smaller than or equal to the value of the second operand then it returns true as (6 <= 6) return true

Example

#include<stdio.h>
#include<conio.h>
void main()
{

int =x;
clrscr();

x= 6<=6
printf("%d",x);

getch();
}

 

Output

Output will be 1 because it is true that 6 is equal to 6.

[>=] operator

What is ‘Greater than equal to’ operator?

This operator is called Greater than equal to operator. It is used to check the value of the first operand greater than and equal to the value of the second operand. If the value of the first operand is greater than or equal to the value of the second operand then it returns true as (4> = 4) return true

Example

#include<stdio.h>
#include<conio.h>
void main()
{

int =x;
clrscr();

x= 4>=4
printf("%d",x);

getch();
}

 

Output

Output will be 1 because it is true that 4 is equal to 4.

[==] operator

What is ‘equal to’ operator?

This operator is called equal to operator. This operator is used to equal check two values. If both values are equal then it returns true.

Example

#include<stdio.h>
#include<conio.h>
void main()
{

int =x;
clrscr();

x= 4==4
printf("%d",x);

getch();
}

 

Output

Output will be 1 because it is true that 4 is equal to 4.

[!=] operator

What is ‘not equal to’ operator?

This operator is called Not equal to operator. This is used to check that the two operands are not equal. Meaning that this operator is used to check the value of two operands, if the value of both operands is not equal then it returns true.

Example

#include<stdio.h>
#include<conio.h>
void main()
{

int =x;
clrscr();

x= 3!=4
printf("%d",x);

getch();
}

 

Output

Output will be 1 because it is true that 3 is not equal to 4.

I hope you would understand the use of relational operators

Note-: “<, >, <=,>=” these operators have high priority and “==, !=” these operators have low priority.

Means if any program contains more than two relational operators then it solves according to its priority. If they have same priority than it solves left to right rule.

Let’s take an example for better understanding

Example

 #include<stdio.h>
#include<conio.h>
void main()
{

int =x;
clrscr();

x= 5<4<3
printf("%d",x);

getch();
}

 

Output

It will be 0.

Explanation:

Computer first solve 5<4 and it give 1 answer after that computer solve 1<3 and this not true and hence computer give 0 answer.

conclusion

We have covered in this post are given below

What are relational operators

Rules of relational operators

What is ‘less then operator’?

What is ‘greater then operator’?

What is ‘Less than equal to operator’?

What is ‘Greater than equal to’ operator?

What is ‘equal to’ operator?

What is ‘not equal to’ operator?

Priority of operators


Also read

(https://grapsvs.blogspot.com/2020/05/arithmetic-instruction-in-c-part-3.html)

(https://grapsvs.blogspot.com/2020/04/Input-Output-instruction-in-C-part-7.html)

 

Thanks for reading this post 

 


Post a Comment

1 Comments

  1. for any quarry please comment me on comment box and also follow me on Instagram

    ReplyDelete

Please do not enter any spam link in the comment box and please follo me.