What is the difference between delete and delete[] in C++?

Options

  • A. Delete is syntactically correct but delete[] is wrong and hence will give an error if used in any case
  • B. Delete is used to delete normal objects whereas delete[] is used to delete pointer objects
  • C. Delete is used to delete single object whereas delete[] is used to delete multiple (array/pointer of) objects
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. Delete is used to delete single object whereas delete[] is used to delete multiple (array/pointer of) objects

Detailed Explanation

Answer: Delete is used to delete single object whereas delete[] is used to delete multiple array objects

In C++, delete is normally used for memory allocated for a single object using new.

delete[] is used when memory was allocated for an array using new[].

For example:

int *p = new int;
delete p;

For an array:

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