+ 3
What is a dangling pointer?
2 Answers
+ 3
If u know basics of dynamic memory allocation.....
then when we allocate memory then a pointer to start of memory is returned say by syntax like int *p =(*int)malloc(size in bytes);
But when u use free function to clear the memory.....
The memory gets cleared and pointer is NOT POINTING TO ANYTHING..SUCH POINTER KNOWN AS DANGLING POINTERS
0
An addition to Saurabh B's answer: Those "loose hanging" pointers can be avoided by setting
*p = NULL
after free'ing it and checking via e.g.
if (*p == NULL) return 0;