C relational operator



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 –

OperatorMeaning
>Greater than
>=Greater than or equal to
<=Less than or equal to
<Less than
#91;/table#93;

Relation operator programs

Program #1 : Relational Operator comparison

#include<stdio.h>
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);
printf("Value of %d <=%d is %d" num1 num2 num1<=num2);
printf("Value of %d < %d is %d" num1 num2 num1< num2);
return(0);
}
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.
OperatorMeaning
==Is equal to
!=Is not equal to
#include<stdio.h>
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);
    return(0);
}

Output :

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