C – Relational Operators

Relational operators in C:

  • Relational operators are used to find the relation between two variables. i.e. to compare the values of two variables in a C program.
S.noOperators
Example 
Description
1>x > yx is greater than y
2<x < yx is less than y
3>=x >= yx is greater than or equal to y
4<=x <= yx is less than or equal to y
5==x == yx is equal to y
6!=x != yx is not equal to y

Example program for relational operators in C:

  • In this program, relational operator (==) is used to compare 2 values whether they are equal are not.
  • If both values are equal, output is displayed as ” values are equal”. Else, output is displayed as “values are not equal”.
  • Note : double equal sign (==) should be used to compare 2 values. We should not single equal sign (=).
#include <stdio.h>
int main()
{
int m=40,n=20;
if (m == n)
{
printf(“m and n are equal”);
}
else
{
printf(“m and n are not equal”);
}
}

Output:

m and n are not equal

projectbandya

No comments:

Post a Comment