GATE CS 2021 (Afternoon) — Question 59

Programming in CFunctions, Parameter Passing, Scope Rules, RecursionNAT2 marksHard

Consider the following ANSI C program:
c
1#include <stdio.h>
2int foo(int x, int y, int q)
3{
4    if ((x <= 0) || (y <= 0))
5        return q;
6    if (x <= 0)
7        return foo(x, y - q, q)
8    if (y <= 0)
9        return foo(x - q, y, q);
10    return foo(x, y - q, q) + foo(x - q, y, q);
11}
12int main( )
13{
14    int r = foo(15, 15, 10);
15    printf("%d", r);
16    return 0;
17}
18
The output of the program upon execution is _________.
Practise the full 2021-AN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAPractise this subject in the exam simulatorTimed, GATE-style tests with analytics that find your weak topics.
Practise more on Functions, Parameter Passing, Scope Rules, RecursionTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group