Relational Operators in C | Comparison operators in C

Relational Operators in C | Comparison operators in C

These operators are used to perform comparison between values . Various relational operators in C language are as follows:

 1. < [Less Than]

Less Than operator is represented as (<) sign. It is used to check whether one value is smaller than another value or not.

Examples

10 < 3 = 0
 3 <10= 1



2. <= [Less Than Equal To]

Less Than Equal To operator is represented as (<=) sign. It is used to check whether one value is smaller than or equal to another value or not.

Examples

10 <= 3  = 0
3 <= 10 = 1
3 <= 3   = 1

3. > [Greater Than]

Greater Than operator is represented as (>) sign. It is used to check whether one value is larger than another value or not.

Example

10 > 3 = 1
3> 10 = 0

4. >= [Greater Than Equal To]

Greater Than Equal To operator is represented as (>=) sign. It is used to check whether one value is larger than or equal to another value or not.

Example

10 >= 3 = 1
3 >= 10 = 0
3 >= 3   = 1



5. Equality comparison(= =)

This operator is represented as double equal to (= =) sign. It is used to check whether one value is equal to another value or not.

Example

10 = = 3 = 0
10 = = 10 = 1

6. Not Equal To(!=)

This operator is represented as sign of exclamation followed by an equal to sign (!=). It is used to check whether one value is not equal to another value.

Example

10 ! = 3 != 1
10 ! = 10 != 0

Program to demonstrate relational operators in C

#include<stdio.h>
int  main()
{
int a=10,b=3;
printf("%d",(a>b));  /*1*/
printf("%d",(a>=b)); /*1*/
printf("%d",(a<b));  /*0*/
printf("%d",(a<=b)); /*0*/
printf("%d",(a==b)); /*0*/
printf("%d",(a!=b)); /*1*/
return (0);
}


Spread the love
Lesson tags: compare values in c, comparison operators of c, Relational Operators in C
Back to: C Programming Language
Spread the love