ProgrammingHardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { int sum = 0, i; for (i = 4; i < 25; i += 4) if (i % 3 == 2) sum += i; printf("%d %d", sum, i); return 0; }

  1. A. 28 24
  2. B. 28 28
  3. C. 28 25
  4. D. 52 28

Correct answer: B. 28 28

The loop visits 4, 8, … while i < 25; qualifying values add up to 28; after the loop i is the first value ≥ 25, i.e. 28.

More C Programming questions

Exams that ask this topic