141k views
4 votes
Assume the following variable definitions int a = 5, b = 12; double x = 3.4, z = 9.1. What are the values of the following expressions?

a) x * a.
b) static_cast(x) * static_cast(z).
c) static_cast(x * z).
d) static_cast(b).

User AlexFZ
by
5.3k points

1 Answer

1 vote

Answer:

a) 17, b) 27, c) 30, d) 12

Step-by-step explanation:

a) x * a

3.4 * 5 = 17

b) static_cast<int>(x) * static_cast<int>(z)

Casting a value to int makes it an integer. The above one equals int(3.4) * int(9.1) = 3 * 9 = 27

c) static_cast<int>(x * z)

Casting a value to int makes it an integer. The above one equals int(3.4 * 9.1) = int(30.94) = 30

d) static_cast<double>(b)

12

User Bill Ticehurst
by
5.5k points