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
write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.
Who developed c language and when?
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
Is javascript based on c?
What is c language used for?
How pointers are declared?
What is function definition in c?
How do I get a null pointer in my programs?
What is variable initialization and why is it important?
Explain low-order bytes.
What's the total generic pointer type?
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
What is const volatile variable in c?
Explain the difference between getch() and getche() in c?
What is array within structure?