Answer Posted / roshan.p.r.
Consider the following example..
int *p=new int[10];
here ten bytes of memory is allocated and the address is
stored in p. the only way to access this memory is via p.
now suppose if u allocate a new memory to p like
p=new int[20];
the previous address(10 bytes is lost we cant access it
again)because the only way that we had to access it was
pointer p and now a new address(20 bytes) is stored in p.
So we say there is a memory leak.
the best way to handle this is.
int *p=new int[10];
[]delete p;
p=0;
p=new int[20];
so in the above case we have first released the memory
pointed by p with delete function and then a new address is
assigned to it.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is a pointer value and address in c?
Explain the use of 'auto' keyword
What is C language ?
How can I open files mentioned on the command line, and parse option flags?
Can we declare function inside main?
What are directives in c?
What is the purpose of type declarations?
What is a void pointer in c?
What are the restrictions of a modulus operator?
What are the types of c language?
a program that can input number of records and can view it again the record
Explain what is the heap?
how to make a scientific calculater ?
What are the different types of errors?
Is main a keyword in c?