What is the last valid index of an array declared as int nums[8]; in C++?

Options

  • A. 8
  • B. 7
  • C. 6
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 7

Detailed Explanation

Correct Answer: Option B — 7

Explanation: An array of 8 elements has indices from 0 through 7. Accessing nums[8] is out of bounds and results in undefined behavior if evaluated.