Function


Question 1
Consider the following program:

int main()
{
  f1();
  f2(2);
  f3();
  return(0);
}

int f1()
{
  return(1);
}

int f2(int X)
{
  f3();
  if (X==1)
     return f1();
  else
     return (X*f2(X-1));
}

int f3()
{
  return(5);
}


Which one of the following options represents the activation tree corresponding to the main function?

A
A
B
B
C
C
D
D
GATE CSE 2023   C Programming
Question 2
The integer value printed by the ANSI-C program given below is ______.
#include < stdio.h >
int funcp(){
   static int x = 1;
   x++;
   return x;
}
int main(){
   int x,y;
   x = funcp();
   y = funcp()+x;
   printf("%d\n", (x+y));
   return 0;
}
A
2
B
5
C
7
D
9
GATE CSE 2023   C Programming


Question 3
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 ____
A
10
B
60
C
180
D
220
GATE CSE 2021 SET-2   C Programming
Question 4
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 __________
A
17
B
15
C
255
D
5
GATE CSE 2021 SET-2   C Programming
Question 5
Consider the following ANSI C function:
 int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex=1; loopIndex<=n-1; loopIndex++)
    total=x*total +Y[loopIndex];
return total;
}
Let Z be an array of 10 elements with Z[i]=1, for all i such that 0\leq i \leq 9. The value returned by SimpleFunction(Z,10,2) is __________
A
1023
B
511
C
255
D
2047
GATE CSE 2021 SET-1   C Programming




There are 5 questions to complete.

15 thoughts on “Function”

  1. Question number 12 of functions of c programming there is typing mistake in question itself . Instead f () you have written if. Please do change it 🙏

    Reply
  2. Question number 86 of functions in c programming
    Correct question
    int Trial (int a, int b, int c)
    {
    if ((a >= b) && (c =b) return Trial(a, c, b);
    else return Trial(b, a, c);
    }

    Reply

Leave a Comment