Function: GATE CS Previous Year Questions

Function · Programming in C

68 questions · asked in 26 of 27 years (2000–2026)

MCQ 47 · NAT 211-mark 35 · 2-mark 33

2000Questions per year2026

Questions 46–50 of 68

Q46GATE 20071 markMCQ−0.33 if wrong
Consider the program below in a hypothetical programming language which allows global variables and a choice of static or dynamic scoping.
int i ;
program main ()
{
    i = 10;
    call f();
}

procedure f()
{   
    int i = 20;
    call g ();
}
procedure g ()
{   
    print i;
} 

Let x be the value printed under static scoping and y be the value printed under dynamic scoping. Then, x and y are:

Q47GATE 20071 markMCQ−0.33 if wrong
Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing.
int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f (i, j);
    print i, j;
}
procedure f (x, y)
{           
    i = 100;
    x = 10;
    y = y + i ;
} 

Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?

Q48GATE 20071 markMCQ−0.33 if wrong
The function f is defined as follows:
 int f (int n) {
    if (n <= 1) return 1;
    else if (n % 2  ==  0) return f(n/2);
    else return f(3n - 1);
}

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.

i. The function f terminates for finitely many different values of n≥1n \geq 1.
ii. The function f terminates for infinitely many different values of n≥1n \geq 1.
iii. The function f does not terminate for finitely many different values of n≥1n \geq 1.
iv. The function f does not terminate for infinitely many different values of n≥1n \geq 1.

Which one of the following options is true of the above?

Q49GATE 20071 markMCQ−0.33 if wrong
Consider the following C function:
 #include <stdio.h>
int f(int n)
{
    static int r = 0;
    if (n <= 0) return 1;
    if (n > 3)
    {
        r = n;
        return f(n-2)+2;
    }
    return f(n-1)+r;
}
 
int main()
{
    printf("%d", f(5));
} 
What is the value of f(5)?

Q50GATE 20061 markMCQ−0.33 if wrong
The following function computes the value of (mn)\binom{m}{n} correctly for all legal values mm and nn (m≥1,n≥0 and m>n)(m \geq 1, n \geq 0 \text{ and } m \gt n)
 int func(int m, int n)
{
    if (E) return 1;
    else return(func(m -1, n) + func(m - 1, n - 1));
}
In the above function, which of the following is the correct expression for E?

Keep practising

Topics in Programming in C

All CS topics ›