When we dynamically allocate memory is there any way to free memory during run time?
Answer: A
Correct answer: Yes
free returns a block to the allocator at any point during execution, and the storage becomes available for later allocations. That is the whole point of the heap: its lifetimes are under the program's control rather than tied to function entry and exit.
The control brings responsibility. Failing to free leaks memory, freeing twice corrupts the allocator's bookkeeping, and using a pointer after freeing it is undefined behaviour - the three faults that dominate debugging in C.
Please log in or register to report this question.