Free Practice Quiz Question List

6 Arrays and Collections Online Quiz Questions

Use this free practice quiz with 20 questions to review 6 Arrays and Collections, test your knowledge, and prepare for your next test or exam.

20 questions
01
True or false
1 point

True or false: For a built-in C++ array containing N elements, the valid indexes are 0 through N - 1.

  1. A

    True

  2. B

    False

02
Choose one
1 point

What is the value of values after this declaration? int values[4] = {7};

  1. A

    {7, 7, 7, 7}

  2. B

    {7, 0, 0, 0}

  3. C

    {0, 0, 0, 7}

  4. D

    The declaration is invalid because every element needs an initializer

03
Written response
1 point

What is the worst-case time complexity of the introductory linear search described for an array?

04
Fill in the blank
1 point

Complete both statements. If fewer initializers are supplied than an array contains, the remaining elements are . If the bound is omitted in int primes[] = {2, 3, 5};, the bound is from the initializer list.

05
Choose one
1 point

Which range-based for loop correctly allows each element of int values[] = {1, 2, 3}; to be modified in place?

  1. A

    for (int value : values)

  2. B

    for (int& value : values)

  3. C

    for (const int& value : values)

  4. D

    for (int* value : values)

06
True or false
1 point

True or false: A function that receives a built-in array parameter automatically knows how many elements the original array contains.

  1. A

    True

  2. B

    False

07
Written response
1 point

Given int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};, what integer value does matrix[1][2] produce?

08
Choose all
1 point

Select all correct statements about std::array<int, 4>.

  1. A

    It stores exactly the number of elements specified by its second template argument.

  2. B

    It automatically changes size whenever elements are added.

  3. C

    It provides a .size() member function.

  4. D

    It supports standard container operations and iterators.

09
Fill in the blank
1 point

Complete the rule for a two-dimensional array parameter: in void printMatrix(const int matrix[][3], std::size_t rows), the inner dimension has elements, and only the bound may be omitted.

10
Choose one
1 point

Which statement correctly computes a fractional average from an integer sum and an integer element count count?

  1. A

    double average = sum / count;

  2. B

    double average = static_cast<int>(sum) / count;

  3. C

    double average = static_cast<double>(sum) / count;

  4. D

    int average = static_cast<double>(sum / count);

11
Choose all
1 point

Select all practices that represent a problem described in the material.

  1. A

    Using i <= 5 to traverse int values[5]

  2. B

    Reading values[0] from an uninitialized automatic array

  3. C

    Using i < 5 to traverse all five elements

  4. D

    Assuming sizeof(values) inside an array-parameter function gives the original array's element count

12
Open ended
1 point

Explain why a function that accepts a built-in array parameter should usually receive an element count separately. Then describe one alternative that preserves the array's complete type and size.

13
Choose one
1 point

In what order are the elements stored contiguously for int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};?

  1. A

    1, 4, 2, 5, 3, 6

  2. B

    1, 2, 3, 4, 5, 6

  3. C

    1, 2, 4, 5, 3, 6

  4. D

    1, 3, 5, 2, 4, 6

14
True or false
1 point

True or false: A built-in C++ array can be copied and assigned as an ordinary object, just like a std::array.

  1. A

    True

  2. B

    False

15
Choose one
1 point

Which range contains all valid indexes for the declaration int scores[4];?

  1. A

    0 through 4

  2. B

    0 through 3

  3. C

    1 through 4

  4. D

    1 through 3

16
Choose one
1 point

What does char word[] = "cat"; contain?

  1. A

    The array contains only the three visible letters.

  2. B

    The array contains the letters plus a space character.

  3. C

    The array contains the letters plus a terminating null character.

  4. D

    The declaration is invalid because the bound is omitted.

17
Choose one
1 point

Which range-based for loop correctly doubles every element of int values[] = {2, 4, 6};?

  1. A

    int value : values

  2. B

    const int& value : values

  3. C

    int& value : values

  4. D

    const auto value : values

18
Choose one
1 point

What are the elements of int values[5] = {10, 20}; after initialization?

  1. A

    {10, 20, 10, 20, 10}

  2. B

    {10, 20, 0, 0, 0}

  3. C

    {10, 20} with only two elements

  4. D

    The declaration is invalid because five initializers are required

19
Written response
1 point

What is the average of int scores[] = {80, 75, 90, 85};? Give the result as a decimal value.

20
Written response
1 point

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