Relational Operators in C

The relational operators are used to perform the relational operation between two operands or variables. e.g. comparison, equality check, etc.

<  If an expression is x < y, it will return TRUE if and only if x is less than y, otherwise it will return FALSE.

<= If an expression is x <= y, it will return TRUE if and only if x is less than or equal to y, otherwise it will return FALSE.

> If an expression is x > y, it will return TRUE if and only if x is greater than y, otherwise it will return FALSE.

>= If an expression is x >= y, it will return TRUE if and only if x is greater than or equal to y, otherwise it will return FALSE.

== If an expression is x == y, it will return TRUE if and only if x is equal to y, otherwise it will return FALSE.

!= If an expression is x != y, it will return TRUE if and only if x is not equal to y, otherwise it will return FALSE.

Here is a C program to demonstrate the relation operators.

/**
* To demonstrate the relational operators
*/
#include<stdio.h>
int main ( int argc, char **argv )
{
int x = 10;
int y = 12;
/* For x < y */
if ( x < y )
{
printf( " x < y : TRUE\n" );
}
else
{
printf( " x < y : FALSE\n" );
}
/* For x <= y */
if ( x <= y )
{
printf( " x <= y : TRUE\n" );
}
else
{
printf( " x <= y : FALSE\n" );
}
/* For x > y */
if ( x > y )
{
printf( " x > y : TRUE\n" );
}
else
{
printf( " x > y : FALSE\n" );
}
/* For x >= y */
if ( x >= y )
{
printf( " x >= y : TRUE\n" );
}
else
{
printf( " x >= y : FALSE\n" );
}
/* For x == y */
if ( x < y )
{
printf( " x == y : TRUE\n" );
}
else
{
printf( " x == y : FALSE\n" );
}
/* x != y */
if ( x != y )
{
printf( " x != y : TRUE\n" );
}
else
{
printf( " x != y : FALSE\n" );
}
return 0;
}

Hope, it would be helpful.

To contribute :

If you like Advance Computing and would like to contribute, you can  mail your article to “computingadvance@gmail.com”. You will get credit as your name , email id, designation with article on this blog.

Leave a Reply