| Relational operators ('<', '>', '<=' and '>=')

Previous | Binary operators | Next

The relational operators are used to compare relative values. They use the following syntax:

    expr1 < expr2
    expr1 > expr2
    expr1 <= expr2
    expr1 >= expr2

In all relational expressions, the operands must conform to one of the following sets of conditions:

1. Both expr1 and expr2 are of arithmetic type. In this case, the usual arithmetic conversions are performed and the result is of type `int`.
2. Both expr1 and expr1 are pointers to qualified or unqualified versions of compatible object types.

When the operands are of arithmetic type:

- expr1 < expr2 gives 1 (true) if the value of expr1 is less than value of expr2; otherwise, the result is 0 (false).
- expr1 <= expr2 gives 1 (true) if the value of expr1 is less than or equal to the value of expr2; otherwise, the result is 0 (false).
- expr1 > expr2 gives 1 (true) if the value of expr1 is greater than the value of expr2; otherwise, the result is 0 (false).
- expr1 >= expr2 gives 1 (true) if the value of expr1 is greater than or equal to the value of expr2; otherwise, the result is 0 (false).

When the operands are of compatible pointer types, the result depends on the relative addresses of the two objects being pointed at.
Floating point comparisons are internally executed using the fcmp function. See the description of this function for more info about rules of comparisons for floating point values.