What is a C++ built-in array?
A built-in array is a fixed-size sequence of elements of one type stored in contiguous memory.
Study 06 Arrays with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is a C++ built-in array?
A built-in array is a fixed-size sequence of elements of one type stored in contiguous memory.
What should a range-based loop use to modify array elements?
Use a reference, such as `for (int& value : values)`, when the loop must modify the original elements.
What indices are valid for an array with N elements?
For an array with N elements, valid indices run from 0 through N−1.
What is the general syntax for declaring a one-dimensional array?
The declaration syntax is `type name[size];`. The size specifies how many elements the array contains.
What happens when an initializer has too few values?
The remaining elements are value-initialized; for an integer array, they become 0.
How can C++ deduce a built-in array's size?
The compiler deduces the bound from the number of supplied initializers, so `int primes[] = {2, 3, 5, 7, 11};` creates five elements.
Why does `char word[] = "hello";` contain six characters?
The terminating null character `\0` is included, so `char word[] = "hello";` contains six characters.
What happens when a built-in array is accessed out of bounds?
Accessing an index outside 0 through size−1 produces undefined behavior; C++ does not automatically check built-in array bounds.
How can code compute a local built-in array's element count?
For an array in its original scope, `sizeof(values) / sizeof(values[0])` computes its element count.
Why cast the sum when computing an array average?
Cast the sum to `double` before division, as in `static_cast<double>(sum) / count`, to avoid integer division.
How are indices interpreted in `int matrix[2][3]`?
In `int matrix[2][3]`, the first index selects one of two rows and the second selects one of three columns.
Which index varies fastest during multidimensional initialization?
The rightmost index varies fastest: initialization proceeds through `matrix[0][0]`, `matrix[0][1]`, `matrix[0][2]`, then the second row.