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.
You might also like to view...
If an Excel workbook is saved as a Single File Web Page, it will have the ________ file extension
A) .xlsx B) .xlsb C) .mht D) .xps
Which of the following should a technician be cautious of when removing a fuser from a printer that has been recently operational?
A. The fuser being fragile B. The fuser being wet C. The fuser being hot D. The fuser containing toner