Govt. Exams
Entrance Exams
Advertisement
Topics in C Programming
Which header file must be included to use malloc(), calloc(), and free() functions?
Correct Answer:
B. #include
EXPLANATION
All memory allocation and deallocation functions are declared in <stdlib.h>.
How much memory is allocated by malloc(sizeof(int) * 10) on a 32-bit system where sizeof(int) = 4?
Correct Answer:
B. 40 bytes
EXPLANATION
sizeof(int) * 10 = 4 * 10 = 40 bytes on a 32-bit system.
Which function is used to free dynamically allocated memory?
Correct Answer:
C. free()
EXPLANATION
free() is the standard function to deallocate memory previously allocated by malloc(), calloc(), or realloc().
What does calloc() do differently from malloc()?
Correct Answer:
B. Initializes memory to zero
EXPLANATION
calloc() takes two arguments (number of elements and size) and initializes all allocated bytes to zero, unlike malloc().
Which header file is required for dynamic memory allocation functions?
Correct Answer:
B.
EXPLANATION
The <stdlib.h> header file contains declarations for malloc(), calloc(), realloc(), and free() functions.