Free Online Flashcard Deck

06 Arrays Free Online FlashCards

Study 06 Arrays with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is a C++ built-in array?

Back

A built-in array is a fixed-size sequence of elements of one type stored in contiguous memory.

02
Front

What should a range-based loop use to modify array elements?

Back

Use a reference, such as `for (int& value : values)`, when the loop must modify the original elements.

03
Front

What indices are valid for an array with NN elements?

Back

For an array with NN elements, valid indices run from 00 through N−1N-1.

04
Front

What is the general syntax for declaring a one-dimensional array?

Back

The declaration syntax is `type name[size];`. The size specifies how many elements the array contains.

05
Front

What happens when an initializer has too few values?

Back

The remaining elements are value-initialized; for an integer array, they become 00.

06
Front

How can C++ deduce a built-in array's size?

Back

The compiler deduces the bound from the number of supplied initializers, so `int primes[] = {2, 3, 5, 7, 11};` creates five elements.

07
Front

Why does `char word[] = "hello";` contain six characters?

Back

The terminating null character `\0` is included, so `char word[] = "hello";` contains six characters.

08
Front

What happens when a built-in array is accessed out of bounds?

Back

Accessing an index outside 00 through size−1size-1 produces undefined behavior; C++ does not automatically check built-in array bounds.

09
Front

How can code compute a local built-in array's element count?

Back

For an array in its original scope, `sizeof(values) / sizeof(values[0])` computes its element count.

10
Front

Why cast the sum when computing an array average?

Back

Cast the sum to `double` before division, as in `static_cast<double>(sum) / count`, to avoid integer division.

11
Front

How are indices interpreted in `int matrix[2][3]`?

Back

In `int matrix[2][3]`, the first index selects one of two rows and the second selects one of three columns.

12
Front

Which index varies fastest during multidimensional initialization?

Back

The rightmost index varies fastest: initialization proceeds through `matrix[0][0]`, `matrix[0][1]`, `matrix[0][2]`, then the second row.