What value will z have if we execute int z = 50 / 10.00;


What value will z have if we execute the following assignment statement?


int z = 50 / 10.00;

a) 5

b) 5.0

c) 50

d) 10

e) none of the above, a run-time error arises because z is an int and 50 / 10.00 is not

Answer: e. Explanation: Because 10.00 is not an int, the division produces a double precision value which cannot be stored in the int z. For this to work, the result of the division must be cast as an int before being stored in z, or the value 10.00 would have to first be cast as an int before the division takes place.