Which of the following header files must necessarily be included to use dynamic memory allocation functions?
Answer: A
Correct answer: stdlib.h
stdlib.h declares malloc, calloc, realloc and free, along with size_t.
Including it matters more than it may appear. Without the prototype, an older compiler assumes malloc returns int, and on a machine where a pointer is wider than an int the returned address is truncated - a fault that a cast to the target type will silence rather than reveal. That is one of the strongest arguments against casting the result in C.
Please log in or register to report this question.