HP C A.06.05 Reference Manual

Expressions and Operators
Relational Operators (>, >=, <, ==, !=)
Chapter 5 127
while (j == 5)
do_something();
The first version is syntactically legal, since all expressions have a value. The value of the
expression j=5is 5. Since this is a nonzero value, the while expression will always evaluate
to true and do_something() will always be invoked.
Relational Operators Precedence Rules
Relational operators have lower precedence than arithmetic operators. The expression
a + b * c < d / f
is evaluated as if it had been written
(a + (b * c)) < (d / f)
Among the relational operators, >, >=, <, and <= have the same precedence. The == and !=
operators have lower precedence. All of the relational operators have left-to-right
associativity. The following table illustrates how the compiler parses complex relational
expressions.
Table 5-12 Examples of Expressions Using the Relational Operators
Given the following declaration:
int j = 0, m = 1, n = -1;
float x = 2.5, y = 0.0;
Expression Equivalent Expressions Result
j > m j > m 0
m / n < x (m / n) < x 1
j <= m >= n ((j <=m) >= n) 1
j <= x == m ((j <= x) == m) 1
- x + j == y > n > m ((-x) + j) == ((y > n) >=
m)
0
x += (y >= n) x = (x + (y >= n)) 3.5
++j == m != y * 2 ((++j) == m) != (y * 2) 1