GATE / CS ARCHIVE

GATE CSE 2026 SET 2 / QUESTION 17

Locating dynamically allocated storage

Programming in C · Scope, Lifetime & Storage Classes · Full GATE CSE 2026 Set 2 paper

GATE 2026 Set 2, Q17 1 mark · MCQ
Report issue

Scope, Lifetime & Storage Classes

Question 17, GATE 2026: In the conventional C runtime model, which object is stored in the heap? A function-local static variable; B ordinary function-local integer array; C integer array allocated by malloc; D function return address.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Givens and goal

In the conventional C runtime model, which object is stored in the heap? A function-local static variable; B ordinary function-local integer array; C integer array allocated by malloc; D function return address.

Approach

Compare storage duration and allocation mechanism rather than source-code location.

Step-by-step solution

1. malloc requests dynamically allocated storage whose lifetime extends until it is released, typically by free. Conventional runtimes manage this storage in the heap. Thus C is the intended answer.
2. A local static variable exists for the program lifetime and conventionally occupies a static data region, despite its name having block scope. Scope does not determine storage duration.
3. An ordinary non-static local array has automatic storage duration and is conventionally placed in a stack frame. A return address is part of calling state, often on a stack or in an architecture-specific register.
4. A local pointer holding the malloc result can itself be in a stack frame while the array it points to is in the heap. The C standard specifies storage behavior, not physical regions literally named stack and heap; the answer uses the stated runtime convention.

Original paper, page 14 · Answer key