GATE 2007 Computer Science and Information Technology (CS) Questions with Solutions

GATE 2007

184 questions

MCQ 1841-mark 184

Questions 71–75 of 184

Q71Function1 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:

Q72Function1 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?

Q73Function1 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?

Q74Function1 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)?

Q75Array and Pointer1 markMCQ−0.33 if wrong
Consider the C program given below :
 #include <stdio.h>

int main ()    {
    int sum = 0, maxsum = 0,  i,  n = 6;
    int a [] = {2, -2, -1, 3, 4, 2};
    for (i = 0; i < n; i++)    {
            if (i == 0 || a [i]  < 0  || a [i] < a [i - 1])  {
                     if (sum > maxsum) maxsum = sum;
                     sum = (a [i] > 0) ? a [i] : 0;
            }
            else sum += a [i];
    }
    if (sum > maxsum) maxsum = sum ;
    printf ("%d\n", maxsum);

}

What is the value printed out when this program is executed?