What is a dangling pointer?

A dangling pointer is a pointer to memory that is no longer allocated. The pointer still points to the memory which earlier was allocated for the data. The data is deleted and the memory may now be used with some other purpose.

{
char *danglingPointer = NULL;
/* … */
{
char localChar;
danglingPointer = &localChar;
}
/* Memory was allocated to danglingPointer in the block. */
/* As soon as program is out of block dandlingPointer points to Memory, */
/* which is free for other use.*/
}

Related Post

What is a double pointer? Why is it required? Is it necessary in C++?

Comments

Leave a Reply




Technology