Could you please explain this? I didn't catch it.
Why should we set the pointer to NULL after deallocating memory?
After deallocating memory, set the pointer to NULL. This prevents accidentally referring to that memory, which may have already been allocated for another purpose.
Null is a special value that we give to pointers to signal that they do not point to anything. It is not necessary but it allows you to check if the pointer is null (there is no way to check if a pointer is uninitialized or dangling) and, like salem c said, if you accidentally try to dereference a null pointer it will usually crash the program instead of accessing deallocated memory (that might now be used by something else) and cause all kind of havoc.
If the pointer goes out of scope right after so that it cannot be used later then I would say it's not necessary to set it to null but if it is a pointer that lives on for longer it's usually a good idea to set it to null.