Relational operators are basically used for comparison purposes. By using relational operators, we often compare two quantities and take a decision based on the result. The result of the relational operator is either 1(if true) or 0(if false), which means 3>1 results in 1.
Operators that are used for all the arithmetic operations are listed below.
Operator | Meaning | Description |
---|---|---|
< | is less than | compare two built-in types of data. x < y, it checks if x is less than y. The result is 1 if x is less than y |
<= | is less than or equal to | |
> | is greater than | For x > y, It results in 1 if x is greater than y otherwise 0 |
>= | is greater than or equal to | |
== | equal to | It checks whether to built-in types of data are equal or not. The result is 1 if they are equal otherwise 0. |
!= | not equal to | The result will be 1 if comparing values are not equal, otherwise 0. |
Examples:
#include <stdio.h>
int main(){
// variable declaration and initialization
int x = 10;
int y = 20;
int z = 21, a = 21;
printf("x < y = %d\n", x < y);
printf("y < x = %d\n", y < x);
printf("z == a = %d\n", z == a);
printf("z <= a = %d\n", z <= a);
printf("z != y = %d\n", z != y);
return 0;
}
Expected Output:
x < y = 1
y < x = 0
z == a = 1
z <= a = 1
z != y = 1