ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
int a[] = {1, 2, 3, 4, 5, 6};
int s = 0;
for (int *p = a; p < a + 6; p += 2) s += *p * p[1];
printf("%d", s);
  1. A. 21
  2. B. 48
  3. C. 44
  4. D. 35

Correct answer: C. 44

p visits a[0], a[2], a[4], and p[1] is the element just after each: 1·2 + 3·4 + 5·6 = 2 + 12 + 30 = 44. '21' is the plain sum of the array.

More C Programming questions

Exams that ask this topic