GATE CS 2017 (Forenoon) — Question 36

Programming in CFunctions, Parameter Passing, Scope Rules, RecursionMCQ2 marks · −2/3 if wrongMedium

Consider the C functions foo and bar given below:
c
1int foo (int val) {
2    int x = 0;
3    while (val > 0) {
4        x = x + foo (val --);
5    }
6    return val;
7}
8int bar (int val) {
9    int x = 0;
10    while (val > 0) {
11        x = x + bar (val -1);
12    }
13    return val;
14}
15
Invocations of foo (3) and bar (3) will result in :
  1. A
    Return of 6 and 6 respectively.
  2. B
    Infinite loop and abnormal termination respectively.
  3. C
    Abnormal termination and infinite loop respectively.
  4. D
    Both terminating abnormally.
Practise the full 2017-FN paper
Challenge a friend: WhatsApp Telegram
From RENYXERAFree All-India Mock — every SundayA full GATE CS paper, exactly 180 minutes, ranked across India with your GATE score.
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