Say I have the following C++ code:
void f() {
MyClass *p = new Class();
delete p;
}
Here, I avoided a memory leak because I deleted whatever that was in the heap. My question is, do I need to make p a null pointer, to avoid it from being a dangling pointer, like so: p = nullptr;
I think the answer is I don't need to make it point to null because when we go out of scope of the function, everything that's on the stack is deleted automatically, meaning that the pointer p is automatically deleted.