Relational operators in C are used to compare two values or expressions and determine the relationship between them. They are commonly used in decision-making statements such as if, if-else, while, and for loops to control the flow of a program based on conditions.
- Used to compare two operands or expressions.
- Always return 1 (true) or 0 (false).
- Commonly used in conditional and looping statements.
Types of C Relational Operators
There are a total of 6 relational operators in C language. There are:

1. Equal to operator (==)
The C equal to operator (==) is a relational operator that is used to check whether the two given operands are equal or not.
- Equal to operator is a binary operator hence it requires two operands to perform the comparison.
- If the two values are equal, it returns true. Otherwise, it returns false.
Syntax
operand1 == operand2
For example, 5==5 will return true.
2. Not equal to operator (!=)
The C not equal (==) to operator is another relational operator used for checking whether the two given operands are equal or not.
- It is also a binary operator, requiring two operands to perform the comparison.
- It is the exact boolean complement of the '==' operator which returns true if the two values are not equal, false otherwise.
Syntax
operand1 != operand2
For example, 5!=5 will return false.
3. Greater than operator (>)
The greater than operator is a relational operator in C that checks whether the first operand is greater than the second operand or not.
- If the operand first is greater than the operand2, it returns true. Otherwise, it returns false.
- This operator is used to make decisions or create conditions based on the relative magnitude of two values.
Syntax
operand1 > operand2
For example, 6>5 will return true.
4. Less than operator (<)
The less than operator is a relational operator in C that checks whether the first operand is lesser than the second operand.
- If the operand first is less than the operand2, it returns true. Otherwise, it returns false.
- This operator is also used to make decisions or create conditions based on the relative magnitude of two values.
Syntax
operand1 < operand2
For example, 6<5 will return false.
Note: The greater than and less than operator are not equal to the complement of each other.
5. Greater than or equal to operator (>=)
The greater than or equal to the operator is a relational operator in C that checks whether the first operand is greater than or equal to the second operand.
- It is a binary operator.
- If the first operand is greater than or equal to the second operand, it returns true. Otherwise, it returns false.
Syntax
operand1 >= operand2
For example, 5>=5 will return true.
6. Less than or equal to the the operator (<=)
The less than or equal to the operator is a relational operator in C that checks whether the first operand is less than or equal to the second operand.
- It is a binary operator.
- If the first operand is less than or equal to the second operand, it returns true. Otherwise, it returns false.
Syntax
operand1 <= operand2
For example, 5<=5 will also return true.
Example of Relational Operator in C
#include <stdio.h>
int main()
{
int a = 10, b = 4;
// greater than example
if (a > b)
printf("a is greater than b\n");
else
printf("a is less than or equal to b\n");
// greater than equal to
if (a >= b)
printf("a is greater than or equal to b\n");
else
printf("a is lesser than b\n");
// less than example
if (a < b)
printf("a is less than b\n");
else
printf("a is greater than or equal to b\n");
// lesser than equal to
if (a <= b)
printf("a is lesser than or equal to b\n");
else
printf("a is greater than b\n");
// equal to
if (a == b)
printf("a is equal to b\n");
else
printf("a and b are not equal\n");
// not equal to
if (a != b)
printf("a is not equal to b\n");
else
printf("a is equal b\n");
return 0;
}
Output
a is greater than b a is greater than or equal to b a is greater than or equal to b a is greater than b a and b are not equal a is not equal to b
Explanation: In this program, different relational operators are used to compare the values of a (10) and b (4). Since 10 is greater than 4, the conditions a > b, a >= b, and a != b evaluate to true, while a < b, a <= b, and a == b evaluate to false. Based on these results, the corresponding messages are printed to the console.
Advantages of Relational Operators in C
- Enable Decision Making: Help programs make decisions using conditions in
if,if-else, andswitchstatements. - Support Loop Control: Used in loops such as
while,for, anddo-whileto control execution. - Easy Value Comparison: Allow comparison of variables, constants, and expressions efficiently.
- Return Simple Results: Produce either
1(true) or0(false), making conditions easy to evaluate. - Improve Program Logic: Help implement validation, searching, sorting, and other logical operations.
- Increase Code Readability: Make conditional expressions concise and easy to understand.
- Widely Used in Algorithms: Essential for implementing comparison-based algorithms and data processing tasks.