1 2 3 4 5 6 7 8 9 10 11 12

[16.11] What if I forget the [] when deleteing array allocated via
new T[n]?

All life comes to a catastrophic end.

[16.12] Can I drop the [] when deleting array of some built-in type
(char, int, etc)?

No!
Sometimes programmers think that the [] in the delete[] p only exists so the compiler will call the appropriate destructors for all elements in the array. Because of this reasoning, they assume that an arrayof some built-in type such as char or int can be deleted without the []. E.g., they assume the following is valid code:

void userCode(int n)
{
char* p = new char[n];
// ...
delete p;
// <-- ERROR! Should be delete[] p !
}

24-Mar-98

Page 11

TAM/C201