Q19
What is the purpose of the 'free' function in C when used with pointers?
A.
Allocate memory
B.
Deallocate memory
AnswerC.
Create a new pointer
D.
Modify the pointer's value
Answer: Option B
Solution
Answer: Option B
Solution:
The 'free' function in C is used to deallocate memory that was previously allocated using functions like malloc, calloc, or realloc.When memory is allocated dynamically, it resides in the heap, and it is the programmer's responsibility to release that memory when it is no longer needed.
Using 'free' helps prevent memory leaks by returning the allocated memory back to the system.
Option A is incorrect because allocating memory is done using
malloc, calloc, or realloc.Option C is incorrect because 'free' does not create new pointers.
Option D is incorrect because 'free' does not modify the value of the pointer; it only releases the memory the pointer points to.
Therefore, the correct answer is Option B: Deallocate memory.