Machine-translated by Google. Questions are authored in English.
Top

Discussion

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

Answer: C

The item stored in the heap is a dynamically allocated array of integers created using malloc().

In a C program the heap is the region managed by malloc(), calloc(), realloc() and free(). Memory obtained from malloc() stays allocated until it is freed, independent of function calls, which is exactly what the heap is for.

A static variable declared inside a function lives in the static data segment (.data or .bss), not on the heap. An ordinary array declared inside a function is an automatic variable on the stack, and the return address of a function is pushed onto the stack as part of its activation record.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.