Relational Operators in  C Language

This “Relational Operators in C Language” post giving information about available relational operators in c, associativity, Priority and Use of these operators using suitable examples.


 

Relational Operators:

  • Relational operators compare two operands and determine the validity of a relationship.
  • Returns 1, if the relation is true
  • Returns 0, if the relation is false
  • Operators are  >, <, >= ,<= , == , !=

 

  • To check the relation between two operands, first we must execute those two operands.
  • for example…. a = ++b >= –c ;
  • Here ++b & –c execute first and then we should evaluate the relation.

Operator                            Symbol    
Greater than                          >
Less than                               <
Greater than or equals         >=
Less than or equals              <=
Equality                                 ==
Inequality                              !=

 

#include<stdio.h>
main()
{
int a=5,b=3,c=7,d=5,e,f,g,h;
e = a++  !=  d–;
f = ++b  ==  d++;
g = c–  >=  ++d;
h = ++d  >=  ++a;
printf(“%d,%d,%d,%d,%d,%d,%d,%d”, a,b,c,d,e,f,g,h);
}

Note : arithmetic operators having higher priority than relational operators.
#include<stdio.h>
main()
{
int a=5 , b=2 , c=3, d, e;
d = a == b + c;
e = (a == b) – c;
printf(“%d,%d\n”,d,e);
}

Note : All the relational operators having equal priority (left -> right evaluation).
#include<stdio.h>
main()
{
int a=35, b=15, c=25,d;
d = a > c > b;
printf(“%d”,d);
}

Share this