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 = 6; i < 24; i += 4) if (i % 2 == 1) sum += i; printf("%d %d", sum, i); return 0; }

  1. A. 22 26
  2. B. 1 26
  3. C. 0 26
  4. D. 0 24

Correct answer: C. 0 26

The loop visits 6, 10, … while i < 24; qualifying values add up to 0; after the loop i is the first value ≥ 24, i.e. 26.

More C Programming questions

Exams that ask this topic