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 f(void) { static int c = 0; c += 7; return c; } int main(void) { int s = 0; for (int i = 0; i < 5; i++) s += f(); printf("%d %d", s, f()); return 0; }

  1. A. 105 42
  2. B. 105 7
  3. C. 140 42
  4. D. 35 7

Correct answer: A. 105 42

The static c persists: successive returns are 7, 14, …, 35; their sum is 105; the next call returns 42.

More C Programming questions

Exams that ask this topic