Question:

In C runtime environment, which one of the following is stored in heap?

Show Hint

Match each item to its memory region: static variables and globals go to the data segment, ordinary local variables and return addresses go to the stack, and anything obtained via malloc/calloc/realloc goes to the heap.
Updated On: Jul 7, 2026
  • A static variable declared inside a function
  • An array of integers declared inside a function
  • A dynamically allocated array of integers created using malloc() function call
  • Return address of a function
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: In a typical C runtime environment, memory used by a program is organized into distinct regions: the code (text) segment, the data segment (for static and global variables), the stack, and the heap.

Step 2: A static variable declared inside a function is stored in the data segment, not the heap, because static variables have a fixed memory location that persists for the entire program lifetime and is allocated at compile/load time, not the heap.

Step 3: An array of integers declared as a normal local variable inside a function (for example <code>int arr[10];</code>) is an automatic variable and is stored on the stack, since its lifetime is limited to the function call.

Step 4: A dynamically allocated array created using <code>malloc()</code> is explicitly requested from the heap at runtime. The heap is exactly the region the C runtime uses for dynamic memory allocation functions like <code>malloc</code>, <code>calloc</code>, and <code>realloc</code>, so this array resides in the heap.

Step 5: The return address of a function is stored on the stack as part of the function's activation record (stack frame), not the heap.

\[ \boxed{\text{Option (C): Dynamically allocated array using malloc() is stored in the heap}} \]
Was this answer helpful?
0
0

Top GATE CS Computer Science and IT Engineering Questions

View More Questions

Top GATE CS Programming in C Questions