Relational Operators in C
The relational operators in C are used for the comparison of the two operands. All these operators are binary operators that return true or false values as the result of comparison.
These are a total of 6 relational operators in C:
S. No. | Symbol | Operator | Description | Syntax |
---|---|---|---|---|
1 | < | Less than | Returns true if the left operand is less than the right operand. Else false | a < b |
2 | > | Greater than | Returns true if the left operand is greater than the right operand. Else false | a > b |
3 | <= | Less than or equal to | Returns true if the left operand is less than or equal to the right operand. Else false | a <= b |
4 | >= | Greater than or equal to | Returns true if the left operand is greater than or equal to right operand. Else false | a >= b |
5 | == | Equal to | Returns true if both the operands are equal. | a == b |
6 | != | Not equal to | Returns true if both the operands are NOT equal. | a != b |
Example of C Relational Operators
// C program to illustrate the relational operators
#include <stdio.h>
int main()
{
int a = 25, b = 5;
// using operators and printing results
printf("a < b : %d\n", a < b);
printf("a > b : %d\n", a > b);
printf("a <= b: %d\n", a <= b);
printf("a >= b: %d\n", a >= b);
printf("a == b: %d\n", a == b);
printf("a != b : %d\n", a != b);
return 0;
}
Output
a < b : 0 a > b : 1 a <= b: 0 a >= b: 1 a == b: 0 a != b : 1
Here, 0 means false and 1 means true.
Operators in C
In C language, operators are symbols that represent operations to be performed on one or more operands. They are the basic components of the C programming. In this article, we will learn about all the built-in operators in C with examples.