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

GATE 2005

203 questions

MCQ 2031-mark 203

Questions 91–95 of 203

Q91Function1 markMCQ−0.33 if wrong
What is the output printed by the following program?
 #include <stdio.h>
int f(int n, int k) {
    if (n == 0) return 0;
    else if (n % 2) return f(n/2, 2*k) + k;
    else return f(n/2, 2*k) - k;
}

int main () {
    printf("%d", f(20, 1));
    return 0;
}

Q92Function1 markMCQ−0.33 if wrong
Consider the following C-program:

double foo (double); /* Line 1 */
int main()
{
    double da, db;
    // input da
    db = foo(da);
}
double foo(double a)
{
    return a;
}
The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:

Q93Function1 markMCQ−0.33 if wrong
Consider the following C-program:
void foo(int n, int sum)
{
  int k = 0, j = 0;
  if (n == 0) return;
    k = n % 10; 
  j = n / 10;
  sum = sum + k;
  foo (j, sum);
  printf ("%d,", k);
}
  
int main ()
{
  int a = 2048, sum = 0;
  foo (a, sum);
  printf ("%d\n", sum);
    
  getchar();
}
What does the above program print?

Q94Function1 markMCQ−0.33 if wrong
What does the following C-statement declare?
int ( * f) (int * ) ; 

Q95Array and Pointer1 markMCQ−0.33 if wrong
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0.
 i = 0; j = 1;
while (j < n ){
         if (E) j++;
         else if (a[j] - a[i] == S) break;
         else i++;
}
if (j < n) printf("yes") else printf ("no");

Choose the correct expression for E.