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
Can java be faster than c++?
Why do we use structure in c++?
How does com provide language transparency?
Should the this pointer can be used in the constructor?
What doescout<<(0==0) print out a) 0 b) 1 c) Compiler error: Lvalue required
Is it possible to pass an object of the same class in place of object reference to the copy constructor?
Explain about vectors in c ++?
What is the difference between strcpy() and strncpy()?
What is the best ide for c++?
How much do c++ programmers make?
What is the importance of mutable keyword?
Can a new be used in place of old mallocq? If yes, why?
Why null pointer is used?
Explain about Virtual Function in C++?
describe private access specifiers?