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...
Which of the following is not a way a user can interact with a computer?
a. command line b. console interface c. GUI d. All of these are ways for a user to interact with a computer.
?If you want to change the form of the recipient's name used in the greeting line shown in the accompany figure, you should click the option that _____ indicates.
?
A. ?Box 1 B. ?Box 2 C. ?Box 3 D. ?Box 4
Any text after the \\ delimiter, but only to the end of the current line, is taken to be a comment in C++.
Answer the following statement true (T) or false (F)
Which of the following is a valid example of calling a method and sending it a two-dimensional array argument?
A. DisplayArrayContents(int [ , ] anArray); B. DisplayArrayContents(anArray); C. DisplayArrayContents(anArray[10, 2]); D. DisplayArrayContents(int [10, 2] anArray);