ProgrammingVery hardGATE CS · Campus placements

int next(void) { static int c = 0; return ++c; } Each of three calls returns its value, and the three returns are added together. What is the total?

  1. A. 6
  2. B. 3
  3. C. 4
  4. D. 9

Correct answer: A. 6

The static counter keeps its value between calls, so the returns are 1, 2 and 3, summing to 6. An auto counter would return 1 every time and sum to 3.

More C Programming questions

Exams that ask this topic