Top

Discussion

Consider the following program, where are i, j and k are stored in memory?

#include 
#include  
int i;
int main()
{
     int j;
    int *k = (int *) malloc (sizeof(int));
}

 

  • A.i, j and *k are stored in stack segment
  • B.i and j are stored in stack segment. *k is stored on heap.
  • C.i is stored in BSS part of data segment, j is stored in stack segment. *k is stored on heap.
  • D.j is stored in BSS part of data segment, i is stored in stack segment. *k is stored on heap.

Answer: C

 

i is global variable and it is uninitialized so it is stored on BSS part of Data Segment, j is local in main() so it is stored in stack frame, *k is dynamically allocated so it is stored on Heap Segment.

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

Post your comment