RAD Studio
ContentsIndex
PreviousUpNext
The delete Operator With Arrays

Arrays are deleted by operator delete[](). You must use the syntax delete [] expr when deleting an array.

char * p;
void func()
{
   p = new char[10];    //  allocate 10 chars
   delete[] p;          // delete 10 chars
}

Early C++ compilers required the array size to be named in the delete expression. In order to handle legacy code, the compiler issues a warning and simply ignores any size that is specified. For example, if the preceding example reads delete[10] p and is compiled, the warning is as follows:

Warning: Array size for 'delete' ignored in function func()
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!