Relational operators are used to compare two values. There are six (6) operators as listed in the following table.
| Operator | Meaning |
|---|---|
== | Equal to |
!= | Not equal to |
< | Less than |
<= | Less than or equal to |
> | Greater than |
>= | Greater than or equal to |
Relational operators have lower precedence than arithmetic operators. For example, consider the following expression.
x + y > zSince arithmetic operators precede relational operators. The expression is evaluated as
(x + y) > zAssumes that
x, y and z is 2, 3 and 4. Then, the expression is said TRUE. An expression is TRUE if it satisfies the condition and FALSE otherwise. In C, TRUE has the value of 1 while FALSE has the value of 0.There are three (3) logical operators which are AND (
&&), OR (||) and NOT (!). More than one expression can be combined using AND (&&) and OR (||) operators. For example, consider the following expression.a > b && x == yIf both
a > b and x == y are TRUE, the expression returns,1 && 1which will returns 1 (TRUE).
! is used to invert the logical value of an expression. For example,!(x > 2)Assume that
x is 3 then the expression is said to be FALSE.