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 11–15 of 68

Q11GATE 2021 (Session 2)1 markNAT
Consider the following ANSI C function:
int SomeFunction (int x, int y)
{
    if ((x==1) || (y==1)) return 1;
    if (x==y) return x;
    if (x > y) return SomeFunction(x-y, y);
    if (y > x) return SomeFunction (x, y-x);
 
} 
The value returned by SomeFunction(15, 255) is __________

Q12GATE 2021 (Session 2)2 marksNAT
Consider the following ANSI C program
 #include <stdio.h>
int foo(int x, int y, int q) 
    {
        if ((x <= 0) && (y <= 0))
        return q;
        if (x <= 0)
        return foo(x, y-q, q);
        if (y <= 0)
        return foo(x-q, y, q);
        return foo(x, y-q, q) + foo(x-q, y, q);
    }
int main( )
{
    int r = foo(15, 15, 10);
    printf("%d", r);
    return 0;
}
The output of the program upon execution is ____

Q13GATE 20202 marksNAT
Consider the following C functions.
int fun1(int n) {
  static int i = 0;
  if (n > 0) {
    ++i;
    fun1(n-1);
  }
  return(i);
}
int fun2(int n) {
  static int i = 0;
  if (n > 0) {
    i = i + fun1(n);
    fun2(n-1);
  }
  return(i);
}

The return value of fun2(5) is ______

Q14GATE 20202 marksNAT
Consider the following C functions.
int tob(int b, int* arr){
   int i;
   for(i=0; b>0; i++){
      if(b%2) arr[i]=1;
      else    arr[i]=0;
      b = b/2;
   }
   return(i);

}
int pp(int a,int b) {
   int arr[20];
   int i, tot = 1, ex, len;
   ex = a;
   len = tob(b,arr);
   for(i=0; i<len; i++){
      if(arr[i]==1)
         tot = tot * ex;
      ex = ex * ex;
   }
   return(tot);
}

The value returned by pp(3,4) is _____

Q15GATE 20191 markNAT
Consider the following C program:
 
#include <stdio.h>
  int jumble(int x, int y) {
    x = 2 * x + y;
    return x;
  }
int main() {
  int x = 2, y = 5;
  y = jumble(y, x);
  x = jumble(y, x);
  printf("%d\n", x);
  return 0;
}
The value printed by program is __________ .

Keep practising

Topics in Programming in C

All CS topics ›