We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
We would need this delete code if we dynamically allocate memory in another function than main(), because as soon as main() would end, the program will end, and all memory will be freed instantly, but when we use dynamic allocation in a function, other than main(), then that part of memory could be resused somewhere else in the program after that function is executed and hence needs to be freed/deleted.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Variable Sized Arrays
You are viewing a single comment's thread. Return to all comments →
We would need this delete code if we dynamically allocate memory in another function than main(), because as soon as main() would end, the program will end, and all memory will be freed instantly, but when we use dynamic allocation in a function, other than main(), then that part of memory could be resused somewhere else in the program after that function is executed and hence needs to be freed/deleted.