What is the dangling pointer Explain with a proper exampleSo
What is the dangling pointer? Explain with a proper example.
Solution
A dangling pointer is a pointer which nce pointed to some data, but because of memory deallocation, points to an invalid or null data.
Example:
Suppose we declare and allocate some memory to a pointer:
char *temp = malloc(some_size);
Then we de-allocate the memory allocated to the pointer temp by,
free (temp);
After execution of the above statement, temp becomes a dangling pointer.
