Follow Our FB Page << >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

what is memory leak?

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=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

Please Help Members By Posting Answers For Below Questions

List some applications of c programming language?


What is realloc in c?


Which programming language is best for getting job 2020?


Why void main is used in c?


plz let me know how to become a telecom protocol tester. thank you.


What is a shell structure examples?


What are run-time errors?


Explain logical errors? Compare with syntax errors.


Is it possible to use curly brackets ({}) to enclose single line code in c program?


What is the function of multilevel pointer in c?


When should structures be passed by values or by references?


Explain zero based addressing.


in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.


struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer


Differentiate between calloc and malloc.