GATE Computer ScienceModerateGATE CSE · ISRO

int f(int n) { static int c = 0; c = c * 2 + n; return c; } int main() { int a = f(1); int b = f(2); int d = f(3); int e = f(4); printf("%d", a + b + d + e); } What is printed?

  1. A. 16
  2. B. 43
  3. C. 42
  4. D. 39

Correct answer: C. 42

The static c persists: 1, 4, 11, 26; their sum is 42.

More Programming and Data Structures (GATE) questions

Exams that ask this topic