danmarino (Ohio State University (OH), Physics)
"The programmer probably intended to test the condition (x < y andand y < z). The code as written will compile and run, but not as intended. For example, if the prior values of x, y, and z are 44, 66, and 22, respectively, then the algebraic condition “x < y < z” is false. But as written, the code will be evaluated from left to right, as (x < y) < z. First the condition x < y will be evaluated as “true.” But this has the numeric value 1, so the expression (x < y) is evaluated to 1. Then the combined expression (x < y) < z is evaluated as (1) < 66 which is also true. So the output state-ment will execute, erroneously reporting that 44 < 66 < 22."
Follow us on :