0

forget to delete the pointer.

Suppose you write a C/Cpp program in which declare a pointer to dynamically allocate memory to store the ages of 10 students. But you forget to free/delete the pointer . In doing so , what type of bug will occur in program ?

27th Sep 2020, 6:33 PM
Saleem
Saleem - avatar
6 Answers
+ 4
The program will compile and run successfully. But there would be memory leak which means that now your pointer has lost the reference to the allocated memory which is never to be recovered.
27th Sep 2020, 6:59 PM
Avinesh
Avinesh - avatar
+ 9
delete are predefined function in cpp you talking about c program and u mentioning delete. In. C language we using free();
28th Sep 2020, 1:43 AM
ASR
+ 3
Once if your code is run successfully then how could you be sure that when you run the code next time, the same memory address would be allocated. It is never the case. The address the pointer was pointing to previously is lost and next time if you run it then it will allocate a new memory with a new address.
27th Sep 2020, 7:09 PM
Avinesh
Avinesh - avatar
+ 2
A memory leak I presume
27th Sep 2020, 6:35 PM
Odyel
Odyel - avatar
0
forget to delete a pointer . does it not mean that it is still pointing at any object ? then how is it a memory leak ?
27th Sep 2020, 7:05 PM
Saleem
Saleem - avatar
0
Thanks everyone for your time and valuable comments.
29th Sep 2020, 9:11 PM
Saleem
Saleem - avatar