What is the value of the remaining elements when a partially initialized integer array is declared as int a[5] = {10, 20};?

Options

  • A. Garbage values are always stored
  • B. The remaining elements are initialized to zero
  • C. The array declaration becomes invalid
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. The remaining elements are initialized to zero

Detailed Explanation

Answer: (B) The remaining elements are initialized to zero

When an array is initialized with fewer values than its declared size, the remaining elements are initialized to zero.

For example:

int a[5] = {10, 20};

The resulting values are:

a[0] = 10
a[1] = 20
a[2] = 0
a[3] = 0
a[4] = 0

This is an important array-initialization rule for C++.