Question 6
What will be the output of calling test(3) for the C function below?
#include <stdio.h>
void test(int n) {
if (n > 0) {
printf("%d ", n);
test(n - 1);
test(n - 1);
}
}Detailed Solution
test(3): prints 3, calls test(2), then test(2).
test(2): prints 2, calls test(1), then test(1).
test(1): prints 1.
Output sequence: 3 2 1 1 2 1 1.