GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 51-55 of 100

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

Question 51

MCQ · Single Correct 2 mark

What is the return value of find_max(a, 5) for array {3, 9, 2, 8, 5}?

CODE
int find_max(int a[], int n) {
    if (n == 1) return a[0];
    int m = find_max(a, n - 1);
    return (a[n-1] > m) ? a[n-1] : m;
}
Answers for question 51

Question 52

MCQ · Single Correct 2 mark

What will be the output of the following C code?

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

Question 53

MCQ · Single Correct 1 mark

What happens when a recursive call passes an incremented pointer ptr + 1?

Answers for question 53

Question 54

MCQ · Single Correct 1 mark

What is the return value of sum_arr(arr, 4) for array {10, 20, 30, 40}?

CODE
int sum_arr(int *p, int n) {
    if (n <= 0) return 0;
    return *p + sum_arr(p + 1, n - 1);
}
Answers for question 54

Question 55

MCQ · Single Correct 2 mark

What is the output of the following program?

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