Relational operator

Relational operators are used to find the relation between two variables. i.e. to compare the values of two variables in a C program.
Operators
Example/Description
>
x > y (x is greater than y)
<
x < y (x is less than y)
>=
x >= y (x is greater than or equal to y)
<=
x <= y (x is less than or equal to y)
==
x == y (x is equal to y)
!=
x != y (x 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 (=).

OUTPUT:

m and n are not equal

No comments:

Post a Comment