Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is dangling pointers?and what is memory leak?

Answer Posted / kush

a dangling pointer is a pointer which points to a dead location in memory, means the variable or object is exist on that memory location bt that was deleted and pointer is still pointing to that location . this pointer is called dangling pointer.

EX:
int *function()
{
int a=500;
return &a;
}

int main()
{
int *ptr;
ptr=function();
++*ptr;
printf("%d",*ptr);//output=501
}
in the above example one function is there which is having return type int * means this function retuns a address.
now came int main(), i have creating one pointer *ptr and after that calling the function then whatever the address return by function is stored in *ptr.
but see the storage class of variable a in function it is auto by default and when function execution is end that variable is destroyed and funtion will return the address of variable a.
tha variable is destroy bt my *ptr is still pointing and utilizing that meroy location and data on that location this is called dangling pointer..

thanks...

Is This Answer Correct ?    28 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How come you find out if a linked-list is a cycle or not?

1035


How can you link a c program with a c function?

1074


Why isn't sizeof for a struct equal to the sum of sizeof of each member?

996


what do you mean by volatile variable?

1050


Define pre-condition and post-condition to a member function in c++?

1149


How to declare an array of pointers to integer?

1141


give me an example for testing a program showing the test path .show how the test is important and complex.

2933


Comment on c++ standard exceptions?

1071


What are the various oops concepts in c++?

1035


What is the main purpose of c++?

1065


When is the copy constructor called?

1141


Show the declaration for a static member variable.

996


what Is DCS ? what i will get benefit when i did?

2357


What is srand c++?

1110


What is Destructor in C++?

1182