ProgrammingHardTCS NQT · Infosys

int cnt[3] = {0}; int *p; for (p = cnt; p < cnt + 3; p++) *p = p - cnt; What is the sum of cnt[0] + cnt[1] + cnt[2]?

  1. A. 2
  2. B. 3
  3. C. 6
  4. D. 0

Correct answer: B. 3

p - cnt is the element index, so cnt becomes {0, 1, 2}. The sum is 3.

More C Programming questions

Exams that ask this topic