ProgrammingModerateTCS NQT · Accenture

What does f(6) print?

What does f(6) print?
void f(int n) {
    printf("%d", n);
    if (n > 1) f(n / 2);
    printf("%d", n);
}
  1. A. 631
  2. B. 6316
  3. C. 136631
  4. D. 631136

Correct answer: D. 631136

Each call prints n on the way down and again on the way back up. The calls go 6 → 3 → 1, so the output is 6 3 1, then 1 3 6.

More C Programming questions

Exams that ask this topic