Free Online Flashcard Deck

6 Arrays and Collections Free Online FlashCards

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

12 cards
01
Front

What is a built-in C++ array?

Back

A built-in array stores a fixed number of elements of the same type in contiguous memory.

02
Front

What are the valid indexes of an array with NN elements?

Back

The valid indexes are from `0` through `N - 1`; the last valid index is therefore N−1N - 1.

03
Front

What happens when a C++ array is accessed out of bounds?

Back

Accessing an element outside the array's valid index range produces undefined behavior.

04
Front

What is `int values[5] = {10, 20};` initialized to?

Back

`values` becomes `{10, 20, 0, 0, 0}` because omitted elements are value-initialized.

05
Front

How many elements does `int primes[] = {2, 3, 5, 7, 11};` contain?

Back

`primes` has five elements because C++ deduces the bound from the number of initializers.

06
Front

How many elements does `char word[] = "cat";` contain?

Back

The array contains four characters: `'c'`, `'a'`, `'t'`, and the terminating null character `\0`.

07
Front

When should a range-based loop use a reference?

Back

A range-based loop visits each element directly; use a reference such as `int& value` when the loop must modify elements.

08
Front

What is a two-dimensional C++ array?

Back

A two-dimensional array is an array whose elements are one-dimensional arrays, commonly representing rows and columns of a table.

09
Front

What is `matrix[1][2]` for `{{1,2,3},{4,5,6}}`?

Back

`matrix[1][2]` is `6`: the first subscript selects the second row, and the second selects its third column.

10
Front

How does a linear search examine an array?

Back

A linear search examines elements sequentially from the beginning until it finds a match or reaches the end.

11
Front

What is the worst-case complexity of linear search?

Back

Its worst-case time complexity is O(n)O(n), because it may inspect every element.

12
Front

Why cast the sum when calculating an array average?

Back

Cast the sum to `double` before division, such as `static_cast<double>(sum) / count`; otherwise integer division discards the fractional part.