HP C A.06.05 Reference Manual
Expressions and Operators
Evaluation of Expressions
Chapter 5144
Evaluation of Expressions
Expressions are evaluated at run time. The results of the evaluation are called by product
values. For many expressions, you won't know or care what this byproduct is. In some
expressions, though, you can exploit this feature to write more compact code.
Examples
The following expression is an assignment.
x = 6;
The value 6 is both the byproduct value and the value that gets assigned to x. The byproduct
value is not used.
The following example uses the byproduct value:
y = x = 6;
The equals operator binds from right to left; therefore, C first evaluates the expression x=6.
The byproduct of this operation is 6, so C sees the second operation as
y = 6
Now, consider the following relational operator expression:
(10 < j < 20)
It is incorrect to use an expression like this to find out whether j is between 10 and 20. Since
the relational operators bind from left to right, C first evaluates
10 < j
The byproduct of a relational operation is 0 if the comparison is false and 1 if the comparison
is true.
Assuming that j equals 5, the expression 10 < j is false. The byproduct will be 0. Thus, the
next expression evaluated:
0 < 20
is true (or 1). This is not the expected answer when j equals 5.
Finally, consider the following fragment: