Relational or comparison operator
These operators are used to compare two operands to determine whether they are equal, unequal, or one is greater than the other. The operands can be variables, constants, or expressions that ultimately get evaluated to a numeric value. Characters are also represented internally as integer (by their ASCII value), so we can also compare the characters.
C language has six relational operators and all are binary operators.
SNO
|
Operator
|
Meaning
|
1.
|
<
|
Is less than
|
2.
|
<=
|
Is less than or equal to
|
3.
|
>
|
Is greater than
|
4.
|
>=
|
Is greater than or equal to
|
5.
|
==
|
Is equal to
|
6.
|
!=
|
Is not equal to
|
A simple relational expression contains only one relational operator and takes the following form:
exp1 relational operator exp2
exp1 and exp2 are arithmetic expression, which may be simple constants, variables or combination of them. Let us take an example if a and b are variable and have value 4 and 6 respectively.
Expression Result
a<b 1
a<=b 1
a>b 0
a>=b 0
a==b 0
a!=b 1
Note: When arithmetic expressions are used on either side of a relational operator, the arithmetic expressions will be evaluated first and then the results compared. That is, arithmetic operators have a higher priority over relational operators.