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

Discussion

Which part of the program address space is p stored in the code given below?

int *p = NULL;
    int main()
    {
        int i = 0;
        p = &i;
        return 0;
    }

 

  • A.Code/text segment
  • B.Data segment
  • C.Bss segment
  • D.Stack

Answer: B

Correct answer: Data segment

p is a file-scope variable with an explicit initialiser, so it goes in the data segment, which holds initialised statics and whose contents come from the executable file. (Strictly, a pointer initialised to NULL is all-zero and many toolchains put it in BSS after all; the distinction the question is drawing is between explicitly initialised and not.)

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

Post your comment

Please log in or register to post a comment.