Which method correctly removes an element at a given index from a…

2025

Which method correctly removes an element at a given index from a one-dimensional array in C++?

  1. A.

    Shift all elements after the target index one position left and reduce the array size by one

  2. B.

    Simply reduce the array size without moving any elements

  3. C.

    Swap the element with the last element and reduce the array size without shifting

  4. D.

    Set the element to zero and keep the array size the same

Attempted by 62 students.

Show answer & explanation

Correct answer: A

To remove an element at a given index in C++, shift all subsequent elements one position to the left and decrement the array size. This preserves data integrity while removing the target element.

Explore the full course: Rssb Senior Computer Instructor