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 **pp = &p;
**pp = 20;
printf("%d %d %d", a, *p, **pp);
  1. A. 10 10 10
  2. B. 20 20 20
  3. C. 10 20 20
  4. D. 20 10 20

Correct answer: B. 20 20 20

pp holds the address of p, so **pp dereferences pp to get p, then dereferences p to get a. Assigning 20 through **pp writes directly into a, so all three expressions (a, *p, **pp) now read the same updated value: 20 20 20.

More C Programming questions

Exams that ask this topic