ProgrammingHardProduct-company MCQ pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int a = 10, b = 20, c = 30;
int *ptrs[3] = {&a, &b, &c};
int **pp = ptrs;
for (int i = 0; i < 3; i++) {
    *(*(pp + i)) += 100;
}
printf("%d %d %d", a, b, c);
  1. A. 10 20 30
  2. B. 100 100 100
  3. C. 110 120 130
  4. D. Undefined behaviour: pp + i goes out of bounds

Correct answer: C. 110 120 130

pp points at the first element of the pointer array. *(pp + i) is ptrs[i] (the i-th stored address); dereferencing that again reaches the actual int (a, b, or c) and adds 100 to it. All three loop iterations stay within ptrs's valid bounds (i=0,1,2), so each variable is incremented exactly once: 110 120 130.

More C Programming questions

Exams that ask this topic