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 / rishabh agrawal

A1 - Dangling pointer points to a memory location which is
being removed.
E.g.
int* a = new int;
int *b = a;
delete b;

Now a will be a dandling pointer.

A2 - Memory leaks occur when memory allocated to a pointer
is not deleted and the pointer goes out of scope. This
allocated memory never gets de-allocated and remains in the
heap until the system is restarted.
E.g.
void foo()
{
int* ptr = new int;
*ptr = 10;
...
...
}
Since ptr is allocated memory using 'new', but no 'delete'
is called, hence memory allocated to ptr will leak.

Is This Answer Correct ?    106 Yes 22 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between new() and malloc() in c++?

1134


Write a c program for binary addition of two 8 bit numbers.

4124


Explain the concept of copy constructor?

1056


What happens if a pointer is deleted twice?

1277


Which is most difficult programming language?

1107


What does ctime() do?

1136


What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

1120


Is python written in c or c++?

1153


What methods can be overridden in java?

1274


What do you mean by late binding?

1131


What is pure virtual function? Or what is abstract class?

1063


What is malloc in c++?

1019


What are the manipulators in c++?

1041


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

2074


Describe private, protected and public – the differences and give examples.

1199