ProgrammingHardTCS NQT · Infosys pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int x = 5, y = 10, z = 15;
int *arr[3] = {&x, &y, &z};
int **p = arr;
printf("%d %d %d", *arr[1], **(p + 2), *p[0]);
  1. A. 5 10 15
  2. B. 15 10 5
  3. C. 10 5 15
  4. D. 10 15 5

Correct answer: D. 10 15 5

arr is an array of pointers (array-of-pointers), each pointing at an int. *arr[1] dereferences arr[1] (&y), giving 10. p is a pointer to arr's first element; *(p+2) is arr[2] (&z), so **(p+2) is 15. p[0] is arr[0] (&x), so *p[0] is 5. Output: 10 15 5.

More C Programming questions

Exams that ask this topic