GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 46-50 of 100

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

Question 46

MCQ · Single Correct 2 mark

What will be the output of the following C program?

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

Question 47

MCQ · Single Correct 1 mark

Which statement about direct vs indirect recursion is correct?

Answers for question 47

Question 48

MCQ · Single Correct 1 mark

What is the output of the following C code?

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

Question 49

MCQ · Single Correct 1 mark

What is the recursion tree depth for merge sort on an array of size N?

Answers for question 49

Question 50

MCQ · Single Correct 1 mark

What is the output of calling mystery(3)?

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