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
What is the use of typedef?
What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0
What is c++ course?
You have two pairs: new() and delete() and another pair : alloc() and free(). Explain differences between eg. New() and malloc()
What is the use of c++ programming language in real life?
How can we check whether the contents of two structure variables are same or not?
Explain the difference between c & c++?
How do I run a program in notepad ++?
What does asterisk mean in c++?
What is meant by forward referencing and when should it be used?
What is command line arguments in C++? What are its uses? Where we have to use this?
Why is the function main() special?
What is stack unwinding?
What are the uses of static class data?
What is purpose of abstract class?