Preview

# Relational Operators in C

These operators are used to perform comparison between values in a program. The result of relational expression is always 0 or 1.

Various relational operators in C language are as follows:

• < [Less Than]
• <= [Less Than Equal To]
• > [Greater Than]
• >= [Greater Than Equal To]
• = = [Equal To]
• != [Not equal To]

## 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.

The value may be in the form of a variable, constant or expression.

If the result of relational expression formed by this operator is true, it will return 1 otherwise it will return 0.

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.

If the result of relational expression formed by this operator is true, it will return 1 otherwise it will return 0.

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.

If the result of relational expression formed by this operator is true, it will return 1 otherwise it will return 0.

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.

If the result of relational expression formed by this operator is true, it will return 1 otherwise it will return 0.

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

## 5. Equality comparison(= =)

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

If the result of relational expression formed by this operator is true, it will return 1 otherwise it will return 0.

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

## 6. Not Equal To(!=)

Not Equal To 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.

If the result of relational expression formed by this operator is true, it will return 1 otherwise it will return 0.

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

### Output (Line Wise)

#include<stdio.h>
#include<conio.h>
int  main()
{
int a,b,c;

printf(“\nEnter value of a=”);
scanf(“%d”,&a);
Enter value of a=10
printf(“\nEnter value of b=”);
scanf(“%d”,&b);
Enter value of 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
getch();
return (0);
}

Lesson tags: compare values in c, comparison operators of c, relational operaotors of c
Back to: C Programming Language