# Function

 Question 1
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 1 Explanation:
 Question 2
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 2 Explanation:
 Question 3
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 3 Explanation:
 Question 4
In the following procedure
 Integer procedure P(X,Y);
Integer X,Y;
value x;
begin
K=5;
L=8;
P=x+y;
end
X is called by value and Y is called by name. If the procedure were invoked by the following program fragment
 K=0;
L=0;
Z=P(K,L);
then the value of Z will be set equal to
 A 5 B 8 C 13 D 0
ISRO CSE 2020   C Programming
Question 4 Explanation:
 Question 5
What is the output in a 32 bit machine with 32 bit compiler?
 #include < stdio.h >
rer(int **ptr2, int **ptr1)
{
int *ii;
ii=*ptr2;
*ptr2=*ptr1;
*ptr1=ii;
**ptr1*=**ptr2;
**ptr2+=**ptr1;
}
void main(){
int var1=5, var2=10;
int *ptr1=&var1,*ptr2=&var2;
rer(&ptr1,&ptr2);
printf("%d %d",var2,var1);
}
 A 60,70 B 50,50 C 50,60 D 60,50
ISRO CSE 2020   C Programming
Question 5 Explanation:
 Question 6
Consider the following recursive C function that takes two arguments
 unsigned int rer(unsigned int n, unsigned int r){
if(n>0)return(n%r + rer(n/r,r));
else retturn 0;
}
What is the return value of the function rer when it is called as rer(513,2)?
 A 9 B 8 C 5 D 2
ISRO CSE 2020   C Programming
Question 6 Explanation:
 Question 7
Consider the following C functions. The value returned by pp(3,4) is _____
 A 9 B 81 C 16 D 125
GATE CSE 2020   C Programming
Question 7 Explanation:
 Question 8
Consider the following C functions. The return value of fun2(5) is ______
 A 55 B 25 C 35 D 10
GATE CSE 2020   C Programming
Question 8 Explanation:
 Question 9
Consider the following C program:

#include < stdio.h >
int r(){
int static num=7;
return num--;
}
int main() {
for(r();r();r()) {
printf("%d ",r());
};
return 0;
}
Which one of the following values will be displayed on execution of the programs?
 A 41 B 52 C 63 D 630
GATE CSE 2019   C Programming
Question 9 Explanation:
 Question 10
Consider the following C program:

void convert(int n) {
if (n<0)
printf("%d",n);
else {
convert(n/2);
printf("%d",n%2);
}
}
Which one of the following will happen when the function convert is called with any positive integer n as argument?
 A It will print the binary representation of n and terminate. B It will print the binary representation of n in the reverse order and terminate. C It will print the binary representation of n but will not terminate. D It will not print anything and will not terminate.
GATE CSE 2019   C Programming
Question 10 Explanation:

There are 10 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. • 