Help to DELETE the "DELETE" error

Please look into this code…

It got accepted on commenting the three delete functions at the end, but gives a SIGABRT error on submitting as it is…

Plz Help.

1 Like

IM NOT SURE, but imho pointer is not deleted the object it is pointing to is deleted.

int *p;
delete []p;	// Produces Segmentation Fault
delete p;	// Produces Segmentation Fault 

(1) ordinary delete
Deallocates the memory block pointed by ptr (if not null), releasing the storage space previously allocated to it by a call to operator new[] and rendering that pointer location invalid.

(2) nothrow delete
Same as above (1).

(3) placement delete
Does nothing.

The second and third versions cannot be implicitly called by a delete-array expression (the delete[] operator always calls the first version of this function exactly once for each of its arguments). But these versions are called automatically by a new-expression if any of the object constructions fail (e.g. if the constructor of an object throws while being constructed by a array new-expression with nothrow, the matching operator delete[] function accepting a nothrow argument is called).

int* a = new int[10];
delete[] a;
a = NULL; // a still exists, but it's a dangling pointer now, so we set it to NULL (or 0) 

operator delete[] can be called explicitly as a regular function, but in C++, delete[] is an operator with a very specific behavior: An expression with the delete[] operator, first calls the appropriate destructors for each element in the array (if these are of a class type), and then calls function operator delete[] (i.e., this function) to release the storage.


thanks but i guess the code takes care of that…
it does not delete a null pointer…
then why is this happening?