Relational Operators are Binary operators that return 1 when the expression is true and 0 when the expression is false.
- 3 > 4 results in 0 because 3 is not greater than 4
- 5 == 4 results in 0 because 5 is not equal to 4 (C uses double equals i.e., == operator to determine equality condition)
- 5 >= 5 results in 1 as 5 is either greater or equal to 5
Here is an example illustrating the Relational operators:
#include <stdio.h> int main() { int a = 5; int b = 10; printf (" A = %d, B = %d \n", a, b); printf (" A < B = %d \n", a < b); printf (" A > B = %d \n", a > b); printf (" A == A = %d \n", a == a); 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:

All the above results are self explanatory. Relational operators find their use in decision making statements and in loops to do some special operation when certain condition is met.
For example:
if (value1==value2)
do something
else
do something else
You will learn about it in later stages. Comment below for questions.
Sign up here with your email
ConversionConversion EmoticonEmoticon