Relational Operators in C [Full Information With Examples]
In this series of learning C language, today we are going to talk about the Relational Operators in C
Today we will learn in detail about, what is Relational Operators in C language and what are the types of Relational Operators, and how they are used.
Relational Operators in C
Relational operators are used to make comparisons between any two operands such as -: One operand is equal to another operand or not, to know which of the two operands is bigger and which is smaller Etc.
Relational Operators returns the result as True and False.
Examples of Relational operators are:
- Equal to operator (==)
- Not equal to operator (! =)
- Greater than operator (>)
- Less than operator (<)
- Greater than or equal to operator (> =)
- Less than or equal to operator (<=)
1. Equal to operator (==) -:
This operator checks between given operands whether the operands are equal or not. If both operands are equal then the Equal to operator returns true in the result and if both the operands are not equal then False returns.
Let’s understand this with a program -:
#include <stdio.h>
int main ()
{
int a, b;
printf ("Enter Two Number \n");
scanf ("%d %d", &a, &b);
if (a==b)
{
printf("\n Both Are Equal");
}
else
{
printf("\n Both Are Not Equal");
}
return 0;
}
Output -:
Enter Two Number
10
20
Both Are Not Equal
2. Not equal to operator (! =)
This operator also checks between two given operands, whether the Operands are equal or not, if both operands are equal then the not equal to operator gives the result returns False and if both the operators are not equal then it returns true. This is the special thing of not equal to operator.
Let’s understand this with a program -:
#include <stdio.h>
int main ()
{
int a, b;
printf ("Enter Two Number \ n");
scanf ("%d %d", &a, &b);
if (a!=b)
{
printf ("\n Both Are Equal");
}
else
{
printf ("\n Both Are Not Equal");
}
return 0;
}
Output -:
Enter Two Number
15
15
Both Are Not Equal
In this example, both the operands are equal, but Not equal to operator (! =) Returned false which led to both Are Not Equal in the result.
3. Greater than operator (>)
Greater than operator (>) checks from the given operands whether the first operands are greater than the second operands?. If the first operand is larger then it returns true in the result and if the first operand is not greater than the second operand then it returns False in the result.
Example -:
#include <stdio.h>
int main ()
{
int A, B;
printf ("Enter Two Number \ n");
scanf ("%d %d", &A, &B);
if (A!=B)
{
printf ("\n A is Greater Than B");
}
else
{
printf ("\n A is Smaller Than B");
}
return 0;
}
Output -:
Enter Two Number
20
15
A is greater than B
4. Less than operator (<)
Less than operator (<) checks from the given operands whether the first operand is smaller than the second operand? If the first operand is small, then it returns true in the result and if the first operand is not smaller, then the second operand returns False in the result.
Example -:
#include <stdio.h>
int main ()
{
int A, B;
printf ("Enter Two Number \ n");
scanf ("%d %d", &A, &B);
if (A!=B)
{
printf ("\n A is Less Than B");
}
else
{
printf ("\n A is Greater Than B");
}
return 0;
}
Output -:
Enter Two Number
10
20
A is Less Than B
5. Greater than or equal to operator (> =)
This operator checks from the given operands whether the first operand is greater or equal than the second operands. If the first operand is larger or equal then it returns true in the result and if the first operand is not greater or equal to the second operand, then it returns False in the result.
Example -:
#include <stdio.h>
int main ()
{
int A, B = 5;
printf ("Enter A Number \ n");
scanf ("%d", &A);
if (A>=B)
{
printf ("\n A is Greater Than Or Equal to B");
}
else
{
printf ("\n A is Not Greater Than Or Equal to B");
}
return 0;
}
Output -:
Enter A Number
5
A is Greater Than Or Equal to B
6. Less than or equal to operator (<=)
This operator checks from the given operands whether the first operand is small or equal to the second operand. If the first operand is small or equal, then it returns true in the result and if the first operand is not smaller or equal to the second operand, then it returns False.
Example -:
#include <stdio.h>
int main ()
{
int A = 3, B = 5;
if (A<=B)
{
printf ("\n A is Less Than Or Equal to B");
}
else
{
printf ("\n A is Not Less Than Or Equal to B");
}
return 0;
}
Output -:
A is Less Than Or Equal to B
Read More -:
- What is Operators In C
- Arithmetic Operators In C
- Logical Operators In C
- Bitwise Operators In C
- Assignment Operators In C
- Conditional Operator in C
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
Conclusion
Friends, I hope you have found the answer of your question and you will not have to search about the relation operator in c Language
However, if you want any information related to this post or related to programming language, computer science, then comment below I will clear your all doubts.
If you want a complete tutorial of C language, then see here C Language Tutorial. Here you will get all the topics of C Programming Tutorial step by step.
Friends, if you liked this post, then definitely share this post with your friends so that they can get information about the relation operator in c Language