GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 41-45 of 100

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

Question 41

MCQ · Single Correct 2 mark

What is the output of the following C code?

C
#include <stdio.h>
int fun(int x, int y) {
    if (x == 0) return y;
    return fun(x - 1, x + y);
}
int main(void) {
    printf("%d", fun(4, 3));
    return 0;
}
Answers for question 41

Question 42

MCQ · Single Correct 1 mark

What is printed by calling print_star(3)?

C
void print_star(int n) {
    if (n <= 0) return;
    for(int i=0; i<n; i++) printf("*");
    printf("
");
    print_star(n - 1);
}
Answers for question 42

Question 43

MCQ · Single Correct 1 mark

What is the primary risk of using deep recursion without tail call optimization?

Answers for question 43

Question 44

MCQ · Single Correct 2 mark

What is the output of the C function for call tr(5)?

JAVASCRIPT
int tr(int n) {
    if (n <= 0) return 0;
    return n % 2 + tr(n / 2);
}
Answers for question 44

Question 45

MCQ · Single Correct 1 mark
CODE
Consider the code:
int solve(int n) {
    if (n <= 1) return 1;
    return solve(n - 1) + solve(n - 2);
}
What is the base case condition?
Answers for question 45
Scroll to Top