C relational operator

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Relational operators in c programming is used for specifying the relation between two operands such as greater than,less than and equals.

Relational Operator in C Programming

In C Programming we can compare the value stored between two variables and depending on the result we can follow different blocks using Relational Operator in C.

In C we have different relational operators such as –

Operator Meaning
> Greater than
>= Greater than or equal to
<= Less than or equal to
< Less than

Relation operator programs

Program #1 : Relational Operator comparison

int main()
int num1 = 30;
int num2 = 40;
printf("Value of %d > %dis %d" num1 num2 num1> num2);
printf("Value of %d >=%dis %d" num1 num2 num1>=num2);
printf("Value of %d <=%dis %d" num1 num2 num1<=num2);
printf("Value of %d < %dis %d" num1 num2 num1< num2);
Output :
Value of 30 > 40 is 0
Value of 30 >=40 is 0
Value of 30 <=40 is 1
Value of 30 < 40 is 1
Whenever we use relational operators in printf statement then we get result of the expression either true or false (i.e 0 or 1)
Recommended Article :Using relational operator in expression

Program #2 : Relational Operator Equality

We all know that C does not support boolean data type so in order to compare the equality we use comparison operator or equality operator in C Programming.
Operator Meaning
== Is equal to
!= Is not equal to
int main()
    int     num1 = 30;
    int     num2 = 40;
    printf("Value of %d ==%d is %d",num1,num2,num1==num2);
    printf("Value of %d !=%d is %d",num1,num2,num1!=num2);

Output :

Value of 30 ==40 is 0
Value of 30 !=40 is 1