Explanation of Problem 10
x *= ++y - z--;
In order to evaluate ++y - z--, we must decide which values of y and z to
use..... do we use the current values, or do we increment (decrement) first
and use the new values. In this problem it's both. Because ++y is
pre-increment, we first increment y from 15 to 16. Next look at z--.
This is post-increment, so we use the current value of z, which is 6,
then decrement z. So the steps are:
- increment y from 15 to 16
- use the current value of z (which is 6) and calculate 16 - 6 = 10 as the
value of the expression
- calculate x *= 10 which is equivalent to x = x * 10. Since x is currently
10, this evaluates to x = 10 * 10 which is 100
- now decrement z from 6 to 5
CSEE
|
201
|
201 S'05
|
lectures
|
news
|
resources
|
help |