RAD Studio |  |

The delete Operator With Arrays
See Also
Collapse All

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

Copy Code

    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:

Copy Code

    Warning: Array size for 'delete' ignored in function func()

See Also

The keyword delete

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!