Table of Contents
Relational operators compare two values and produce an integer result. The result is 1 when the relationship is true and 0 when it is false.
#include <stdio.h>
int main()
{
int a = 10;
int b = 20;
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;
}
Example Output #
a < b : 1
a > b : 0
a <= b : 1
a >= b : 0
Explanation #
The relational operators are:
| Operator | Meaning |
|---|---|
< |
Less than |
> |
Greater than |
<= |
Less than or equal to |
>= |
Greater than or equal to |
For example:
a < b
compares 10 with 20. Since 10 is less than 20, the expression produces 1.
Similarly:
a > b
is false, so it produces 0.
The result of a relational operator has type int in C and is either 0 or 1.