After
delete ptr;
the pointer object ptr
probably still holds the same value it had before. It now points to a nonexistent object, so attempting to dereference it, or even to refer to its value, has undefined behavior. If you accidentally do something like:
delete ptr;
// ...
*ptr = 42;
it's likely to quietly clobber memory that you no longer own, or that may have been reallocated to some other object.
Setting the pointer to null:
delete ptr;
ptr = NULL; // or 0 or nullptr
means that an accidental attempt to dereference the pointer is more likely to cause your program to crash. (Crashing is a good thing in this context.)
Stealing Casey's comment:
C++11 §3.7.4.2 Deallocation Functions [basic.stc.dynamic.deallocation] para 4:
If the argument given to a deallocation function in the standard
library is a pointer that is not the null pointer value (4.10), the
deallocation function shall deallocate the storage referenced by the
pointer, rendering invalid all pointers referring to any part of the
deallocated storage. The effect of using an invalid pointer value
(including passing it to a deallocation function) is undefined.
If the pointer object is at the very end of its lifetime, you needn't bother, since there's no possibility of accidentally using it:
{
int *ptr = new int(42);
// ...
delete ptr;
}
And as others have said, you're probably better off using some higher-level construct like smart pointers anyway.