Which operator should be used to release an array allocated using new[] in C++?

Options

  • A. delete
  • B. delete[]
  • C. free[]
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. delete[]

Detailed Explanation

Answer: delete[]

When an array is allocated using new[], it should be released using delete[].

For example:

int *p = new int[5];
delete[] p;

Using ordinary delete instead of delete[] does not correctly match the array allocation and can result in undefined behavior.