1. What is the output of C Program with functions ?
int main()
{
int b=25;
//b memory location=1234;
int *p;
p=&b;
printf(“%d %d “, &b, p);
return 0;
}
A) 25 25
B) 1234 1234
C) 25 1234
D) 1234 25
Ans:B
2. Find output of the following?
int rec(int num){
return (num) ? num%10 + rec(num/10):0;
}
main()
{
printf(“%d”,rec(4567));
}
a) 4
b) 12
c) 22
d) 21
Ans:c
3. Find output of the following?
int something(int number)
{
if(number <= 0)
return 1;
else
return number * something(number-1);
}
main()
{
printf(“%d”,something(4));
}
a) 12
b) 24
c) 1
d) 0
Ans:b
4. what will be the output of func(3,8) .
int func(int a, int b){ if(b==0)
return 0;
if(b==1)
return a; return a + func(a,b-1);
}
a) 11
b) 24
c) 22
d) 21
Ans:b
5. what will be the output of following code:
#include<stdio.h>
print(int n)
{
if (n == 0)
return 0;
printf(“%d”, n%2);
print(n/2);
}
What will be the output of print(12).
a) 00110
b) 11001
c) 10010
d) 10001
Ans:a
6. What will be the output of sum(8).
int sum(int n)
{
if (n==0)
return n;
else
return n + sum(n-1);
}
a)36
b)35
c)34
d)none
Ans:a
7. Which of the following problems can’t be solved using recursion?
a) Factorial of a number
b) Nth fibonacci number
c) Length of a string
d) Problems without base case
Ans:d
8. How many times is the recursive function called, when the following code is executed?
void my_recursive_function(int n)
{
if(n == 0)
return;
printf(“%d “,n);
my_recursive_function(n-1);
}
int main()
{
my_recursive_function(10);
return 0;
}
a) 9
b) 10
c) 11
d) 12
Ans:c
C MCQ Set-11 Explanation
9. What does the following recursive code do?
void my_recursive_function(int n)
{
if(n == 0)
return;
my_recursive_function(n-1);
printf(“%d “,n);
}
int main()
{
my_recursive_function(10);
return 0;
}
a) Prints the numbers from 10 to 1
b) Prints the numbers from 10 to 0
c) Prints the numbers from 1 to 10
d) Prints the numbers from 0 to 10
Ans:c
C MCQ Set-11 Explanation
10. What will be the output of the following code?
int cnt=0;
void my_recursive_function(int n)
{
if(n == 0)
return;
cnt++;
my_recursive_function(n/10);
}
int main()
{
my_recursive_function(123456789);
printf(“%d”,cnt);
return 0;
}
a)123456789
b) 10
c) 0
d) 9
Ans:d