GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 26-30 of 100

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

Question 26

MCQ · Single Correct 2 mark

What is the output of the following code for fun(3)?

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

Question 27

MCQ · Single Correct 1 mark

Which of the following functions is strictly tail-recursive?

Answers for question 27

Question 28

MCQ · Single Correct 1 mark

What is printed by print_rev("ABC")?

CODE
void print_rev(char *s) {
    if (*s == '\0') return;
    print_rev(s + 1);
    putchar(*s);
}
Answers for question 28

Question 29

MCQ · Single Correct 2 mark

What is the output of the following C code?

C
#include <stdio.h>
int f(int n) {
    if (n <= 0) return 1;
    return f(n - 1) + f(n - 2);
}
int main(void) {
    printf("%d", f(4));
    return 0;
}
Answers for question 29

Question 30

MCQ · Single Correct 1 mark

What is the value returned by power(2, 5)?

CODE
int power(int base, int exp) {
    if (exp == 0) return 1;
    if (exp % 2 == 0) {
        int t = power(base, exp / 2);
        return t * t;
    }
    return base * power(base, exp - 1);
}
Answers for question 30
Scroll to Top