What is the value assigned to the variable in each of these cases? Explain curious results. Be careful! int x, y;

a) x = 1/2;
b) y = 3.0/2.0;
double z, w, t;
c) z = 1/2;
d) w = 3/2;
e) t = 3.0/2.0;


a) 0 is assigned.1/2 is computed using truncating integer divide which gives 0.
b) 1.5 is calculated and assigned. The fractional part is discarded; 1 is stored.
c) 0 is calculated because 1/2 is done with truncating integer divide, gives 0. The
floating point value 0.0 is stored.
d) 1 is calculated, because truncating int divide, 1.0 is stored
e) 1.5 is calculated and stored.

Computer Science & Information Technology

You might also like to view...

Operational threats frequently originate from ____.

A. internal sources B. external sources C. known sources D. unknown sources

Computer Science & Information Technology

A moving average calculates an average for a group of numbers over a specified interval allowing you to see ________ for widely fluctuating numbers

A) a constraint B) a scenario C) an objective D) a trend

Computer Science & Information Technology

Which of the following are true of the echo command?

A. When used to display text, quotation marks are optional. B. It can be used to display shell variables by including a $ sign in front of the variable name. C. Including a semicolon at the end of the line will not affect the text being displayed. D. All of the other options are true.

Computer Science & Information Technology

Which of the three protections ensures that only authorized parties can view information?

A. security B. availability C. integrity D. confidentiality

Computer Science & Information Technology