arjunkumar Posted May 12, 2020 Share Posted May 12, 2020 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. @ Quote Link to comment Short link Share on other sites More sharing options...
rohanjoshi0894 Posted May 18, 2020 Share Posted May 18, 2020 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 */ } @ Quote Link to comment Short link Share on other sites More sharing options...
teempade04 Posted January 24, 2023 Share Posted January 24, 2023 (edited) Dangling Pointer occurs when a pointer pointing to a variable goes out of scope or when an object/variable's memory gets deallocated. Also, the occurrence of Dangling Pointers can result in some unexpected errors during the execution of a program, so we have to make sure to avoid them while writing a program. mobdro myfiosgateway.one Edited February 9, 2023 by teempade04 @ Quote Link to comment Short link Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.