Heap allocation is required for the languages that:
Heap allocation is required for the languages that:
- A.
Support recursion
- B.
Support dynamic data structures
- C.
Support recursion and dynamic data structures
- D.
None of the above
Attempted by 293 students.
Show answer & explanation
Correct answer: B
Answer: Languages that support dynamic data structures require heap allocation.
Explanation: The heap is used for memory whose lifetime is controlled at runtime (dynamic allocation).
Dynamic data structures (for example, linked lists, trees, and resizable arrays) need memory allocated and freed at runtime, which is provided from the heap (e.g., malloc or new).
Recursion stores function call activation records on the call stack; recursion alone does not require heap allocation unless the program explicitly performs dynamic allocation.
Therefore, the need for heap allocation stems from supporting dynamic data structures, not from supporting recursion by itself.
Summary: Languages that support dynamic data structures require heap allocation; supporting recursion alone does not.