ProgrammingHardTCS NQT · Infosys pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
int a = 10;
int *p = &a;
int *q = p;
p = NULL;
printf("%d %d", p == NULL, *q);
  1. A. 0 0
  2. B. 1 10
  3. C. 0 10
  4. D. 1 0

Correct answer: B. 1 10

q was assigned a COPY of p's value (the address of a) before p was reassigned to NULL; pointers are ordinary values that get copied on assignment, so changing p afterward has no effect on q at all. p == NULL is true (1), and *q still correctly reaches a, 10.

More C Programming questions

Exams that ask this topic