Computer Sciences > GATE 2026 SET-2 > Programming and Data Structures
In C runtime environment, which one of the following is stored in heap?
A
A static variable declared inside a function
B
An array of integers declared inside a function
C
A dynamically allocated array of integers created using malloc() function call
D
Return address of a function

Correct : c

The correct answer is Option C — A dynamically allocated array of integers created using malloc().
The C runtime memory layout is divided into distinct regions. The stack holds local variables, function parameters, and return addresses — all with automatic lifetime tied to their scope. The BSS/data segment holds global and static variables. The heap is the region explicitly managed by the programmer for dynamic memory allocation.
Option A — Static variable inside a function: The static keyword gives a variable static storage duration regardless of where it is declared. It is stored in the BSS or data segment, persisting for the entire program lifetime. Not heap.
Option B — Array declared inside a function: A locally declared array like int arr[10] inside a function is a local variable with automatic storage duration — it lives on the stack and is destroyed when the function returns. Not heap.
Option C — Dynamically allocated array via malloc(): malloc() explicitly requests memory from the heap at runtime. The programmer is responsible for freeing it using free(). This is the canonical use of heap memory. Heap ✓ Correct.
Option D — Return address of a function: When a function is called, the CPU pushes the return address onto the call stack so execution can resume at the correct point after the function completes. Not heap.

Similar Questions

Consider the following three ANSI-C programs, P1, P2 and P3Which one of the following statements is true?
#1564 MCQ
Consider the following ANSI-C program. The output of this program is ____________. (answer in integer) Note: Assume that the program compiles and runs succ...
#1606 Fill in the Blanks
Consider the following ANSI-C function. The maximum possible value that can be returned from this function is ____________. (answer in integer) Note: Ig...
#1607 Fill in the Blanks

Related Topics

GATE CS 2026 Set-2 Q17 C runtime heap memory GATE 2026 malloc heap allocation GATE CS stack heap BSS segment GATE C memory layout GATE 2026 programming data structures GATE CS 2026 dynamic memory allocation GATE static variable storage GATE CS

Unique Visitor Count

Total Unique Visitors

Loading......