Free Practice Quiz Question List

06 Arrays Online Quiz Questions

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

20 questions
01
Choose one
1 point

Which range contains all valid indices for the C++ declaration int values[4];?

  1. A

    0 through 4

  2. B

    0 through 3

  3. C

    1 through 4

  4. D

    1 through 3

02
Choose one
1 point

What is the resulting sequence of values for int values[5] = {7, 8};?

  1. A

    {7, 8, 7, 8, 7}

  2. B

    The declaration is invalid

  3. C

    {7, 8, 0, 0, 0}

  4. D

    The remaining elements contain indeterminate values

03
Choose one
1 point

Which function parameter declaration is valid for receiving a two-dimensional built-in array whose rows contain four integers?

  1. A

    void process(int data[][4], int rows);

  2. B

    void process(int data[][], int rows);

  3. C

    void process(int data[rows][], int columns);

  4. D

    void process(int data[*][4], int rows);

04
Choose all
1 point

Select all properties that apply to a C++ built-in array.

  1. A

    Their elements are stored in contiguous memory.

  2. B

    They automatically grow when an element is appended.

  3. C

    Their indices begin at zero.

  4. D

    They provide a built-in push_back member function.

  5. E

    Their size is fixed after declaration.

05
Choose all
1 point

Select all statements that correctly describe passing a one-dimensional built-in array to an ordinary function parameter.

  1. A

    void f(const int values[], int size); is equivalent as a parameter declaration to void f(const int* values, int size);.

  2. B

    The function normally needs a separate size argument.

  3. C

    The array's complete size is automatically available inside the function through sizeof(values).

  4. D

    A const element parameter can make the elements read-only through that parameter.

  5. E

    The function receives a copy of every array element.

06
True or false
1 point

True or false: Because a built-in array name often converts to a pointer to its first element, the array itself is a pointer.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: In for (const int& value : values), the loop can read each element but cannot modify it through value.

  1. A

    True

  2. B

    False

08
Written response
1 point

How many elements are in the character array declared by char word[] = "hello";?

09
Written response
1 point

What C++ standard-library type represents a fixed-size array while retaining its size as part of its type?

10
Fill in the blank
1 point

Complete the equivalence: array[index] is equivalent to .

11
Fill in the blank
1 point

In the expression matrix[row][column] for a two-dimensional array, the first index selects a and the second index selects a .

12
Open ended
1 point

A program computes an integer sum and an integral count, then assigns sum / count to a double average. Explain why a cast is important and give a corrected expression for computing the average.

13
Choose one
1 point

Which loop safely visits every element exactly once in int values[4] = {4, 8, 15, 16};?

  1. A

    for (int i = 0; i < 4; ++i)

  2. B

    for (int i = 0; i <= 4; ++i)

  3. C

    for (int i = 1; i < 4; ++i)

  4. D

    for (int i = 0; i < 5; ++i)

14
Choose one
1 point

Which range of indices is valid for the built-in C++ array int scores[5]?

  1. A

    0 through 5

  2. B

    0 through 4

  3. C

    1 through 5

  4. D

    1 through 4

15
Choose one
1 point

What value does values[3] have after this declaration?

int values[5] = {7, 8};

  1. A

    7

  2. B

    8

  3. C

    0

  4. D

    Undefined because the initializer is incomplete

16
True or false
1 point

True or false: A built-in C++ array is itself a pointer because its name often converts to a pointer to the first element.

  1. A

    True

  2. B

    False

17
Choose one
1 point

Which range-based for loop correctly doubles every element of the existing integer array values 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)

18
Written response
1 point

How many elements does this array contain?

int values[] = {3, 6, 9, 12};

19
Choose one
1 point

Given the declaration below, what value does matrix[1][2] refer to?

int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};

  1. A

    3

  2. B

    6

  3. C

    4

  4. D

    5

20
Written response
1 point

In an ordinary one-dimensional function parameter, what complete C++ type does const int values[] become after parameter adjustment?