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 operator overloading in c++ example?
how can i access a direct (absolute, not the offset) memory
address?
here is what i tried:
wrote a program that ask's for an address from the user,
creates a FAR pointer to that adress and shows it. then the
user can increment/decrement the value in that address by
pressing p(inc+) and m(dec-).
NOW, i compiled that program and opened it twice (in 2
different windows) and gave twice the same address to it.
now look what happen - if i change the value in
one "window" of the program, it DOES NOT change in the
other! even if they point to the same address in the memory!
here is the code snippet:
//------------------------------------------------------
#include How does the copy constructor differ from the assignment operator (=)? Define what is constructor? What is a stack? How it can be implemented? What do the header files usually contains? What is the use of data hiding? What is function prototyping? What is function overloading in C++? If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first
a) 1
b) 5
c) 3 Out of fgets() and gets() which function is safe to use? Is c++ double? What is c++ used for in games? What is the maximum combined length of command line arguments including the space between adjacent arguments? What c++ library is string in?