Typical pointer issues in C++
Application run into errors when accessing an unknown/undefined memory location (e.g., dereferencing via uninitialized or deleted pointers). Memory leaks occur when you lose track of a piece of dynamically allocated memory. The following are examples of typical pointer-related issues in C++, which I abbreviate as UNDO (UNinitialized, Deleted, and Overridden) Pointers.
Uninitialized pointer
A NULL pointer is still uninitialized:
Deleted pointer
Dangling pointer is a pointer to a location that had been pointed to by another pointer, which has been deleted. I consider dangling pointer a special case of deleted pointer.
Overridden pointers
A pointer p
points to dynamically allocated memory, and you reassign (overwrite) p
without first deleting it, that memory will be lost and your code will have a memory leak.
Reference
This post is my learning notes summarized from the tutorial Learning a New Programming Language: C++ for Java Programmers.