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 ?
6 odpowiedzi
+ 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.
+ 9
delete are predefined function in cpp you talking about c program and u mentioning delete. In. C language we using free();
+ 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.
+ 2
A memory leak I presume
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 ?
0
Thanks everyone for your time and valuable comments.