# 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 1 Explanation:
 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 2 Explanation:

 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 3 Explanation:
 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 4 Explanation:
 Question 5
Consider the following ANSI C function:
 int SimpleFunction(int Y[], int n, int x)
{
int total = Y, loopIndex;
for (loopIndex=1; loopIndex<=n-1; loopIndex++)
total=x*total +Y[loopIndex];
}
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
Question 5 Explanation:

There are 5 questions to complete.

### 15 thoughts on “Function”

1. Question 65 wrong

• Thank You Abhishek Chavle,
We have updated the question.

• Question number 86 of functions in c programming it should be c<b instead of c=b . Please do change.

• Thank You PRAFUL SAMBHAJI RANE,
We have updated the question.

2. 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 🙏

• Thank You PRAFUL SAMBHAJI RANE,
We have updated the question.

3. 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);
}

• Thank You PRAFUL SAMBHAJI RANE,
We have updated the question.

4. question 58.
2 options are same

• Thank You Bikash Dutta,
We have updated the options.

5. In Ques no-62 there is one small misprint , there will be z=**ppz

6. in Q 60.
z= **ppz

7. Pls separate out ISRO and GATE questions!

8. • 