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 are the 4 types of unions?
can anyone suggest some site name..where i can get some good data structure puzzles???
Explain a pre-processor and its advantages.
Explain the difference between #include "..." And #include <...> In c?
What is the significance of an algorithm to C programming?
write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.
In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping
What is pointers in c?
Write a program to compute the similarity between two strings - The program should get the two strings as input - Then it will output one single number which is the percentage of similarity between the two strings
In c programming, explain how do you insert quote characters (? And ?) Into the output screen?
The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
What is difference between structure and union with example?
how logic is used
What are the application of c?