Answers to Self-Review Exercises
-
array
s,vector
s.array
name, type.subscript or index.
constant variable.
sorting.
searching.
two-dimensional.
-
False. An
array
can store only values of the same type.False. An
array
subscript should be an integer or an integer expression.False. The remaining elements are initialized to zero.
True.
-
const size_t arraySize{10};
array<double, arraySize> fractions{0.0};
fractions[3]
fractions[4]
fractions[9] = 1.667;
fractions[6] = 3.333;
cout << fixed << setprecision(2); cout << fractions[6] << ' ' << fractions[9] << endl; Output: 3.33 1.67
for (size_t i{0}; i < fractions.size(); ++i) { cout << "fractions[" << i << "] = " << fractions[i] << endl; } Output: fractions[0] = 0.0 fractions[1] ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.