Which range contains all valid indices for the C++ declaration int values[4];?
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.
What is the resulting sequence of values for int values[5] = {7, 8};?
- A
{7, 8, 7, 8, 7}
- B
The declaration is invalid
- C
{7, 8, 0, 0, 0}
- D
The remaining elements contain indeterminate values
Which function parameter declaration is valid for receiving a two-dimensional built-in array whose rows contain four integers?
- A
void process(int data[][4], int rows); - B
void process(int data[][], int rows); - C
void process(int data[rows][], int columns); - D
void process(int data[*][4], int rows);
Select all properties that apply to a C++ built-in array.
- A
Their elements are stored in contiguous memory.
- B
They automatically grow when an element is appended.
- C
Their indices begin at zero.
- D
They provide a built-in
push_backmember function. - E
Their size is fixed after declaration.
Select all statements that correctly describe passing a one-dimensional built-in array to an ordinary function parameter.
- A
void f(const int values[], int size);is equivalent as a parameter declaration tovoid f(const int* values, int size);. - B
The function normally needs a separate size argument.
- C
The array's complete size is automatically available inside the function through
sizeof(values). - D
A
constelement parameter can make the elements read-only through that parameter. - E
The function receives a copy of every array element.
True or false: Because a built-in array name often converts to a pointer to its first element, the array itself is a pointer.
- A
True
- B
False
True or false: In for (const int& value : values), the loop can read each element but cannot modify it through value.
- A
True
- B
False
How many elements are in the character array declared by char word[] = "hello";?
What C++ standard-library type represents a fixed-size array while retaining its size as part of its type?
Complete the equivalence: array[index] is equivalent to .
In the expression matrix[row][column] for a two-dimensional array, the first index selects a and the second index selects a .
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.
Which loop safely visits every element exactly once in int values[4] = {4, 8, 15, 16};?
- A
for (int i = 0; i < 4; ++i) - B
for (int i = 0; i <= 4; ++i) - C
for (int i = 1; i < 4; ++i) - D
for (int i = 0; i < 5; ++i)
Which range of indices is valid for the built-in C++ array int scores[5]?
- A
0 through 5
- B
0 through 4
- C
1 through 5
- D
1 through 4
What value does values[3] have after this declaration?
int values[5] = {7, 8};
- A
7
- B
8
- C
0
- D
Undefined because the initializer is incomplete
True or false: A built-in C++ array is itself a pointer because its name often converts to a pointer to the first element.
- A
True
- B
False
Which range-based for loop correctly doubles every element of the existing integer array values in place?
- A
for (int& value : values) - B
for (int value : values) - C
for (const int& value : values) - D
for (int* value : values)
How many elements does this array contain?
int values[] = {3, 6, 9, 12};
Given the declaration below, what value does matrix[1][2] refer to?
int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};
- A
3
- B
6
- C
4
- D
5
In an ordinary one-dimensional function parameter, what complete C++ type does const int values[] become after parameter adjustment?