Jump to content
Korean Random

Recommended Posts

Hello Everyone, I am preparing for my upcoming interview which is c language based. I want to know concept of dangling pointer in C? and In how many ways can a pointer act as a Dangling Pointer? When A pointer is pointing to a memory location, and a B pointer deletes the memory occupied by the A pointer, then the A pointer still points to the memory location? So Can anyone know about it and explains to me with some examples of dangling pointer.

Share this post


Link to post

Short link
Share on other sites

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. 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 */
}

Share this post


Link to post

Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...