Analyze the following fragment:
```
double sum = 0;
double d = 0;
while (d != 10.0) {
d += 0.1;
sum += sum + d;
}
```
a. The program does not compile because sum and d are declared double, but assigned with integer value 0.
b. The program never stops because d is always 0.1 inside the loop.
c. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
d. After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9
c. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
The correct answer is C. There is no guarantee that d will be exactly 10.0 because real numbers are represented using approximation in a computer system.
You might also like to view...
Answer the following statements true (T) or false (F)
1. A C++ declaration introduces only an identifier's spelling and specifies its type. 2. A C++ declaration is a definition that also allocates storage for an identifier's value (or function's body etc.). 3. The range of values for an int variable is from about 0 to +2 billion. 4. The names x, y, and z are satisfactory variable names for the lengths of the legs and hypotenuse of a triangle. 5. In C++ you can assign an expression of type int to a variable of type double with no problem.
The process of sorting data into groups based on value, or sensitivity, is called "____________________."
Fill in the blank(s) with the appropriate word(s).
Answer the following questions true (T) or false (F)
1. Downcasting causes the slicing problem. 2. In C++, a virtual destructor is invoked whenever a virtual constructor was used to create the object.
A Split form shows two records at one time instead of the one record which is normally displayed in a form
Indicate whether the statement is true or false