What is the purpose of the 'free' function in C when used with pointers?
A. Allocate memory
B. Deallocate memory
C. Create a new pointer
D. Modify the pointer's value
Answer: Option B
Solution (By Examveda Team)
The 'free' function in C is used to deallocate memory that was previously allocated using functions likemalloc, 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.
Join The Discussion
Comments (1)
Related Questions on Pointer
In C, what is a pointer primarily used for?
A. Decision making
B. Code organization
C. Variable declaration
D. Storing values
In C, how do you declare a pointer variable that can store the address of an integer?
A. int *ptr;
B. ptr int;
C. int ptr;
D. ptr *int;
What is the purpose of the '->' operator in C when used with pointers?
A. Arithmetic operation
B. Indirection operator
C. Member access operator
D. Bitwise operation

Answer