CPA-21-02 practice question 3 of 35

Which of the following statements are correct about an array? int tab[10];

Full set: 257 questions
Answer options
A: The array can store 10 elements. Correct answer
B: The expression tab[1] designates the very first element in the array.
C: The expression tab[9] designates the last element in the array. Correct answer
D: It is necessary to initialize the array at the time of declaration.
Correct Answer:
A. The array can store 10 elements.; C. The expression tab[9] designates the last element in the array.
Explanation

In C++, the declaration int tab[10]; allocates a contiguous block of memory for an array capable of storing exactly 10 integer elements. C++ arrays utilize zero-based indexing, meaning the index of the first element is 0 and the index of the last element is N-1 (where N is the size of the array). Therefore, tab[0] accesses the first element, and tab[9] correctly designates the tenth and final element in the array.

Why Incorrect

B: Incorrect because C++ arrays are zero-indexed; the expression tab[1] designates the second element in the array, not the first. D: Incorrect because C++ does not mandate array initialization at the time of declaration; uninitialized local arrays simply contain indeterminate (garbage) values.

References

1. ISO/IEC 14882:2017 (C++17 Standard), Section 11.3.4 [dcl.array], Paragraph 1-3 (Array declarations and bounds).

2. Stanford University CS106L Standard C++ Programming, Array and Pointer semantics.

Scroll to Top