In C runtime environment, which one of the following is stored in heap?
GATE CSE 2026Programming in C › Functions & Parameter PassingVerified
GATE CSE 2026 PYQ: In C runtime environment, which one of the following is stored in heap?
- AA static variable declared inside a function
- BAn array of integers declared inside a function
- CA dynamically allocated array of integers created using malloc() function callCorrect answer
- DReturn address of a function
Answer
(C) A dynamically allocated array of integers created using malloc() function call
Approach
Classify each of the four objects by the C storage duration / memory segment it belongs to. A typical C process image has a text (code) segment, a data segment holding statics and globals (with the zero-initialized part often called BSS), a heap that grows upward for dynamic allocation, and a stack that grows downward for automatic variables and call bookkeeping. Matching each option to its segment identifies which object lives in the heap.
Only a dynamically allocated object has dynamic storage duration, and in C that memory is supplied by the heap through malloc(). The static variable (A) goes to the data segment, the local array (B) and the return address (D) go to the stack, so C is the answer.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.