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 26–30 of 68

Q26GATE 2016 (Session 2)2 marksNAT
Consider thefollowingprogram:

int f(int*p, int n)
{
   if (n<=1)return 0;
    else return max(f(p+1,n-1),p[0]-p[1]);
}
int main()
{
    int a[]={3,5,2,6,4};
    printf("%d", f(a,5));
 }
Note: max(x,y) returns the maxi mumof x and y. The value printed by this program is____________ .

Q27GATE 2015 (Session 2)1 markMCQ−0.33 if wrong
Consider the following function written in the C programming language.
   void foo(char *a){
     if ( *a && *a != ' '){
          foo(a+1);
          putchar(*a);
       }
} 
The output of the above function on input "ABCD    EFGH""ABCD \; \; EFGH" is

Q28GATE 2015 (Session 2)1 markNAT
Consider the following C function.
int fun(int n){
   int x=1,k;
   if (n==1) return x;
   for (k=1; k < n; ++k)
       x = x + fun(k) * fun(n-k);
   return x;
}
The return value of fun(5) is ________.

Q29GATE 2015 (Session 3)2 marksMCQ−0.67 if wrong
Consider the following recursive C function.
 void get(int n)
{
if (n<1) return;
get(n-1);
get(n-3);
printf("%d", n);
}
If get(6) function is being called in main()then how many times will the get()function be invoked before returning to the main()?

Q30GATE 2015 (Session 3)2 marksNAT
Consider the following C program.
 #include <stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x = 10;
int main( )
{
   int x = 1;
   x += f1( ) + f2( ) + f3( ) + f2( );
   printf("%d", x);
   return 0;
}
int f1() { int x = 25; x++; return x;}
int f2() { static int x = 50; x++; return x;}
int f3() { x *= 10; return x;}
The output of the program is ________.

Keep practising

Topics in Programming in C

All CS topics ›