What do you mean by dangling pointer? explain with an example?
Answers
Answered by
1
Hey!
1.Dangling pointers arise when an object is deleted or de-allocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the de-allocated memory.
2 .In short pointer pointing to non-existing memory location is called dangling pointer.
Example
#include<stdlib.h> { char *ptr = malloc(Constant_Value); ....... ....... ....... free (ptr); /* ptr now becomes a dangling pointer */ }
Hope It Helps.☺️
1.Dangling pointers arise when an object is deleted or de-allocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the de-allocated memory.
2 .In short pointer pointing to non-existing memory location is called dangling pointer.
Example
#include<stdlib.h> { char *ptr = malloc(Constant_Value); ....... ....... ....... free (ptr); /* ptr now becomes a dangling pointer */ }
Hope It Helps.☺️
Similar questions