I read that you should assign null (0) to all pointers that you call
delete on.
I'd suggest you throw out whatever book said something as stupid
as that. I almost never set pointers to null after delete, and
I don't know of any good programmers that do.
*p=0(set the value pointed to to 0).
After a delete, that would be undefined behavior. Of the worst
kind, since it will almost always work. (The most frequent
result of undefined behavior is for it to work in all of your
tests, and then cause a program crash during the important demo
in front of your most important client.)
p=0(set the address held to zero).
The last one is awkward for none would want a pointer pointing
to address zero(even though it compiles fine, you can´t assign
anything to it).
You're not making the pointer point to the address zero here
(despite appearances). You're making it point to nowhere, but
with a testable and copiable value. It's useful in the rare
cases where you have a pointer which sometimes will point to
something, and othertimes won't. When it doesn't point to
something, you set it to null (which you can write NULL or 0).
This is often used in lazy evaluation (the pointer is
initialized to null; at each use, you test for null, and
evalutate it to the usable value if it is null), or for various
caching schemes (in which case, you do set the pointer to null
after a delete, since that's how you recognize that the cache is
invalid). Most deletes, however, occur in destructors, in which
case, there's no sense in setting the pointer to null, since you
can't use it later anyway.
I find the first still awkward because you are assigning a
value to a place you no longer use.
The first is undefined behavior. Don't do it. The second has
some specialized uses, but there's certainly no reason to do it
systematically after a delete.