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++?
- A.
Shift all elements after the target index one position left and reduce the array size by one
- B.
Simply reduce the array size without moving any elements
- C.
Swap the element with the last element and reduce the array size without shifting
- 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.