GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 6-10 of 100

Your score 0/100 0 answered
Correct 0 Incorrect 0 Unanswered 100 Accuracy 0%

Question 6

MCQ · Single Correct 2 mark

What will be the output of calling test(3) for the C function below?

C
#include <stdio.h>
void test(int n) {
    if (n > 0) {
        printf("%d ", n);
        test(n - 1);
        test(n - 1);
    }
}
Answers for question 6

Question 7

MCQ · Single Correct 1 mark

What is the maximum stack depth (number of stack frames) created when executing recursive factorial(n)?

Answers for question 7

Question 8

MCQ · Single Correct 2 mark

Consider the following recursive function with a static variable:

JAVASCRIPT
int fun(int n) {
    static int x = 1;
    if (n <= 1) return 1;
    x++;
    return fun(n - 1) + x;
}

What does fun(4) return?

Answers for question 8

Question 9

MCQ · Single Correct 1 mark

Which of the following optimization techniques enables a compiler to reuse the current stack frame for recursive calls?

Answers for question 9

Question 10

MCQ · Single Correct 2 mark

What is the output of the following C program?

C
#include <stdio.h>
void p(int n) {
    if (n > 0) {
        p(n - 1);
        printf("%d ", n);
        p(n - 1);
    }
}
int main(void) {
    p(3);
    return 0;
}
Answers for question 10
Scroll to Top