Relational operator in c

Relational operator in c

Relational operators are used to compare values of two expressions. An expression that contains relational operators is known relational expression or called relational expression. if there is relation is true then the value of relational expression is 1 if relation is false then the value of expression is 0. There are some relational operators are- –

Operators Meaning
< Less than
<= Less than or equal to
== equal to
!= Not equal to
> Grater than
>= Grater than or equal to

Lets us take example with applying relational operators let us take two variables x=10 and y=8 and form simple relational expressions with them–

Expression Relation Value of Expression
x<=y false 0
x<=y False 0
x==y False 0
x!=y True 1
x>y True 1
x>=y True 1
x==0 False 0
y!=0 True 1
X>1 True 1
10<20 True 1

Generally the relation operators are used with in the if else statement and loops so now we will used relational operators with if else statement in the next program to understand. if the control statement evaluates any expression and that expression is true or (non zero) then the next statement is evaluated or executed . Otherwise the next statement is skipped or not show so in the below discussed program with relation operator

/*Program to understand the use of relational operators*/
#include
void
main()
{
int x,y;
printf(“Enter the value of x and y”);
scanf(“%d%d”,&x,&y);
if(x>y)
{
printf(“%d is grater then %d\n”,x,y);
}
if(x>=y)
{
printf(“%d is grater then or equal to %d\n”,x,y);
}
if(x==y)
{
printf(“%d is equal to %d\n”,x,y);
}
if(x!=y)
{
printf(“%d is not equal to %d”,x,y);
}
}