ProgrammingHardTCS NQT · Infosys pattern

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

Assume a 64-bit LP64 ABI. What is printed?
int a[5] = {1, 2, 3, 4, 5};
int *start = a;
int *end = a + 5;
int sum = 0;
while (start != end) {
    sum += *start;
    start++;
}
printf("%d", sum);
  1. A. 0
  2. B. 15
  3. C. 10
  4. D. 20

Correct answer: B. 15

start walks from a[0] to one-past-a[4] (a valid, non-dereferenced sentinel), accumulating every element: 1+2+3+4+5=15.

More C Programming questions

Exams that ask this topic