Which header is traditionally associated with malloc(), calloc(), realloc() and free() in C++?

Options

  • A. <iostream>
  • B. <cstdlib>
  • C. <string>
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. <cstdlib>

Detailed Explanation

Answer: (B) <cstdlib>

The C++ header <cstdlib> provides access to several functions originating from the C standard library, including dynamic memory functions such as malloc(), calloc(), realloc() and free().

These functions are available in C++ for compatibility with C-style programming, although modern C++ generally provides higher-level memory-management facilities.

<iostream> is primarily used for input and output, while <string> provides the C++ string class and related functionality.