Consequences of removing a pointer
What you got here is called a drooped pointer - a monster that you would normally like to avoid at all costs.
source to share
When you do delete p
. The memory marked p
is deleted.
delete
~ = destructor + release
Here delete
is just a term that indicates that the memory is freed. Doesn't affect the total memory of the OS or the variable itself p
. p
still points to memory that is now patched by the system and thus becomes a dangling pointer.
source to share
The pointer variable is retained, but its value is rendered invalid - anything with it other than assigning another valid pointer or null pointer gives undefined behavior. There is no guarantee that the pointer value will not change .
source to share