Dangling Pointer
A dangling pointer is a pointer that no longer points to a valid memory location. This situation often occurs when the memory it points to has been deallocated or freed, but the pointer itself has not been updated. Accessing a dangling pointer can lead to unpredictable behavior, including program crashes or data corruption.
To avoid dangling pointers, programmers should set pointers to `NULL` after freeing the memory they point to. This practice helps ensure that any attempt to access the pointer will be safely handled, as dereferencing a `NULL` pointer typically results in a clear error, rather than undefined behavior.