Author Topic: If y is of integer type then the expressions  (Read 361 times)

Offline mechanic

If y is of integer type then the expressions
« on: February 25, 2017, 11:16:46 AM »
Advertisement
Question: If y is of integer type then the expressions

3 * (y -8) / 9 and (y -8) / 9*3

Options are:

A. must yield the same value
B. must yield different value
C. may or may not yield the same value
D. none of the above

Correct answer is:

C. may or may not yield the same value


Explanation:

If y = 11, the expression 3 * (y -8) / 9 becomes 3 * 3 / 9, which evaluates to 1. But the expression (y -8) / 9 * 3 becomes 3 / 9 * 3. which evaluates to 0 (since 3/9 is 0)

Engineering Forum

If y is of integer type then the expressions
« on: February 25, 2017, 11:16:46 AM »