Machine-translated by Google. Questions are authored in English.
Top

Discussion

When we dynamically allocate memory is there any way to free memory during run time?

  • A.Yes
  • B.No

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.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.