ProgrammingHardGATE CS · Campus placements

static int total = 0; int add(int n) { static int t = 0; t += n; return t; } Calls add(3), add(4) and add(5) in that order. What does the last call return?

  1. A. 8
  2. B. 15
  3. C. 12
  4. D. 5

Correct answer: C. 12

The static local t keeps its value across calls, so the running totals are 3, 7 and 12. The file-scope total is unused and does not affect the result.

More C Programming questions

Exams that ask this topic