adplus-dvertising
frame-decoration

Question

Consider the following program. Where are i, j and k are stored in memory?
#include <stdio.h>
#include  <stdlib.h>
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 stored in BSS part of data segment, j is stored in stack segment. *k is stored on heap.

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Consider the following program. Where are i, j and k are stored in memory?