What is Dangling Pointer in Programming?
Dangling Pointer in programming refers to a pointer that doesnât point to a valid memory location. This usually happens when an object is deleted or deallocated, without modifying the value of the pointer, so it still points to the memory location of the deallocated memory.
Example:
int* ptr = new int(5);
delete ptr;
// ptr is now a dangling pointer
Dangling Pointer in programming
In programming especially in C and C++, pointers play a very important role in managing memory and improving performance. However incorrect use of pointers can lead to issues. One such issue is creation of dangling pointers. In this article, we will explore what dangling pointers are how they occur and how to prevent them.
Contact Us