ProgrammingHardWipro · Cognizant pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int a = 5, b = 10, c = 15;
int *arr[3];
arr[0] = &c;
arr[1] = &a;
arr[2] = &b;
int sum = 0;
for (int i = 0; i < 3; i++) sum += *arr[i];
printf("%d", sum);
  1. A. 25
  2. B. 30
  3. C. 0
  4. D. 15

Correct answer: B. 30

arr holds pointers to c, a, b respectively; the loop dereferences each in turn and sums their pointed-to values: 15 + 5 + 10 = 30, regardless of the (deliberately shuffled) order they're stored in.

More C Programming questions

Exams that ask this topic