# C - Relational Operators

C Programming

In this tutorial we will learn about relational operators in C programming language.

C provides us with 6 relational operators.

OperatorDescription
<Is less than
<=Is less than or equal to
>Is greater than
>=Is greater than or equal to
==Is equal to
!=Is not equal to

We use relational operators to compare two quantities. If the condition is satisfied then we get one (true) otherwise, it is zero (false).

## Is less than

In the following example we have two numbers and we are checking if a is less than b.

``````#include <stdio.h>
int main(void)
{
int
a = 10,
b = 20;

if (a < b) {
printf("a is less than b\n");
}
else {
printf("a is not less than b\n");
}
return 0;
}
``````

Output

``````a is less than b
``````

Note! In the above program and in the programs that follows we are using `if-else` conditional statement. If the condition is true or non-zero then the if-block code is executed. Otherwise, the else-block code is executed.

## Is less than or equal to

In the following example we have two numbers and we are checking if a is less than or equal to b.

``````#include <stdio.h>
int main(void)
{
int
a = 10,
b = 20;

if (a <= b) {
printf("a is less than or equal to b\n");
}
else {
printf("a is not less than and not equal to b\n");
}
return 0;
}
``````

Output

``````a is less than or equal to b
``````

## Is greater than

In the following example we have two numbers and we are checking if a is greater than b.

``````#include <stdio.h>
int main(void)
{
int
a = 20,
b = 10;

if (a > b) {
printf("a is greater than b\n");
}
else {
printf("a is not greater than b\n");
}
return 0;
}
``````

Output

``````a is greater than b
``````

## Is greater than or equal to

In the following example we have two numbers and we are checking if a is greater than or equal to b.

``````#include <stdio.h>
int main(void)
{
int
a = 20,
b = 10;

if (a >= b) {
printf("a is greater than or equal to b\n");
}
else {
printf("a is not greater than and not equal to b\n");
}
return 0;
}
``````

Output

``````a is greater than or equal to b
``````

## Is equal to

In the following example we have two numbers and we are checking if a is equal to b.

``````#include <stdio.h>
int main(void)
{
int
a = 10,
b = 10;

if (a == b) {
printf("a is equal to b\n");
}
else {
printf("a is not equal to b\n");
}
return 0;
}
``````

Output

``````a is equal to b
``````

## Is not equal to

In the following example we have two numbers and we are checking if a is not equal to b.

``````#include <stdio.h>
int main(void)
{
int
a = 20,
b = 10;

if (a != b) {
printf("a is not equal to b\n");
}
else {
printf("a is equal to b\n");
}
return 0;
}
``````

Output

``````a is not equal to b
``````

Among the six relational operator, each one is a complement of another operator.

OperatorIs Complement of
<=
>=
==!=