int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a; What number will z in the sample code above contain?
-
12
-
10
-
11
-
6
Evaluating the expression: x++ is post-increment (use 5, then x becomes 6), --y is pre-decrement (y becomes -11), so the expression is 5 - (-11 * 2 / 4) = 5 - (-22/4) = 5 - (-5) = 10. In integer division, -22/4 = -5 (truncates toward zero). Final result: z = 10, x = 6, y = -11. Option B is correct.
To find the value of z in the given code, let's break down the expression step by step:
x++increments the value ofxby 1 after it is used in the expression. So, the value ofxis now 6.--ydecrements the value ofyby 1 before it is used in the expression. So, the value ofyis now -11.y * bmultiplies the value ofy(-11) by the value ofb(2), resulting in -22.-22 / adivides the value of -22 by the value ofa(4), resulting in -5.5.Finally,
z = 6 - (-5.5), which simplifies toz = 6 + 5.5. Therefore,zequals 11.5.
However, since the given variables are integers, the result will be truncated to the nearest integer. So, z will contain the value 11.
Therefore, the correct answer is option C) 11.