Expression | (8 - 2) / 2 | (2 + 6) / 2 - 9 | (8 + 4) * 2 | 8 + 4 * 2 | 8 + (4 * 2) |
---|---|---|---|---|---|
Value? | 3 | -5 | 24 | 16 | 16 |
Notice that the last expression (above) did not need parentheses. It does not hurt to use parentheses that are not needed. For example, all of the following are equivalent:
a + b + c * d | a + b + (c * d) | (a + b) + (c * d) | ((a + b) + (c * d)) |
Warning! Look out for division. The /
operator is a constant source of bugs!
Parentheses will help.
What is the value of each of the following expressions?
Expression | 8 + 2 / 2 + 3 | (8 + 2) / (2 + 3) | (8 + 2) / 2 + 3 | 8 + 2 / (2 + 3) |
---|---|---|---|---|
Value? |