0% found this document useful (0 votes)
67 views

Engineeringinterviewquestions Com Mcqs On Recursion Answers

The document contains a collection of 250 multiple choice questions (MCQs) on the topic of recursion in C programming. It includes questions related to recursive functions, stack implementation, base cases, infinite recursion, and output of sample code snippets involving recursion. Sample questions and answers are provided to illustrate different concepts of recursion. Related posts containing additional recursion questions are listed at the end.

Uploaded by

chiragkaushik558
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Engineeringinterviewquestions Com Mcqs On Recursion Answers

The document contains a collection of 250 multiple choice questions (MCQs) on the topic of recursion in C programming. It includes questions related to recursive functions, stack implementation, base cases, infinite recursion, and output of sample code snippets involving recursion. Sample questions and answers are provided to illustrate different concepts of recursion. Related posts containing additional recursion questions are listed at the end.

Uploaded by

chiragkaushik558
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

HOME Interview Questions MCQs Class Notes *LAB VIVA SEMINAR TOPICS ONLINE TEST GATE CAT Internship

ABOUT US

Any Skill Search Here...

$2,955 $2,046 $9,023 $3,258


#1 Used Car Exporter in Japan
Be Forward

Home » C Programming Objective Questions » 250+ TOP MCQs on Recursion and Answers

250+ TOP MCQs on Recursion and Answers

C Multiple Choice Questions & Answers (MCQs) on “Recursion”.

1. What will be the output of the following C code?

#include
main()
{
int n;
n=f1(4);
printf("%d",n);
}
f1(int x)
{
int b;
if(x==1)
return 1;
else
b=x*f1(x-1);
return b;
}

a) 24
b) 4
c) 12
d) 10

Answer: a
Clarification: The above code returns the factorial of a given number using the method of recursion. The given number is 4
in the above code, hence the factorial of 4, that is, 24 will be returned.

2. The data structure used to implement recursive function calls _____________


a) Array
b) Linked list
c) Binary tree Outsource Software Developers Open
d) Stack Simply Search on The Next Page For Details. Explore Online. Development Solutions
Answer: d
Clarification: The compiler uses the data type stack for implementing normal as well as recursive function calls.

3. The principle of stack is __________


a) First in first out
b) First in last out
c) Last in first out
d) Last in last out

Answer: c
Clarification: A stack is a last in first out(LIFO) data type. This means that the last item to get stored in the stack is the first
item to get out of it.

4. In the absence of a exit condition in a recursive function, the following error is given __________
a) Compile time error
b) Run time error
c) Logical error
d) No error

Answer: b
Clarification: When a recursive function is called in the absence of an exit condition, it results in an infinite loop due to
which the stack keeps getting filled(stack overflow). This results in a run time error.

5. What will be the output of the following C code?

#include
main()
{
int n,i;
n=f(6);
printf("%d",n);
}
f(int x)
{
if(x==2)
return 2;
else
{
printf("+");
f(x-1);
}
}

a) ++++2
b) +++++2
c) +++++
d) 2

Answer: a
Clarification:
When x=6: ‘+’ is printed.
When x=5: ‘+’ is printed.
When x=4: ‘+’ is printed.
When x=3: ‘+’ is printed.
When x=2: 2 is printed.
Hence the output is: ++++2.

6. How many times is ‘a’ printed when the following C code is executed?

#include
main()
{
int a;
a=f1(10);
printf("%d",a);
}
f1(int b)
{
if(b==0)
return 0;
else
{
printf("a");
f1(b--);
}
}

a) 9 times
b) 10 times
c) 0 times
d) Infinite number of times

Answer: d
Clarification: Although we have specified the exit condition, the code above results in an infinite loop because we have used
b- -(decrement operator) to call the recursive function. Due to this, the loop goes on infinitely. However, if we had used f1(b-
1) instead, the answer would have been 10 times.

7. What will be the output of the following C code?

#include
main()
{
int n=10;
int f(int n);
printf("%d",f(n));
}
int f(int n)
{
if(n>0)
return(n+f(n-2));
}

a) 10
b) 80
c) 30
d) Error

Answer: c
Clarification: The recursive function returns n+f(n-2) till 10>0.
Therefore, the above code will be evaluated as: 10+8+6+4+2, which is equal to 30.

8. What will be the output of the following C code?

#include
int main()
{
printf("Hello");
main();
return 0;
}

a) Hello is printed once


b) Hello infinite number of times
c) Hello is not printed at all
d) 0 is returned

Answer: b
Clarification: in the above code, we are calling main() from main(), which is recursion. However, we have not defined any
condition for the program to exit. Hence, “hello” will be printed infinite number of times. To prevent this, we need to define
a proper exit condition in the recursive function.

9. What will be the output of the following C code if the input given to the code shown below is “”?
#include
#define NL 'n'
main()
{
void f(void);
printf("enter the wordn");
f();
}
void f(void)
{
char c;
if((c=getchar())!=NL)
{
f();
printf("%c",c);
}
return;
}

a)
b) infinite loop
c) yrdnuofnas
d) fnasyrdnuo

Answer: c
Clarification: The above code prints the reverse of the word entered. The recursive function terminates when getchar() is
equal to null.

10. Iteration requires more system memory than recursion.


a) True
b) False

Answer: b
Clarification: Recursion requires more system memory than iteration due to the maintenance of stack.

---- >> Below Are The Related Posts Of Above Questions :::

------>>[MOST IMPORTANT]<<------

1. 250+ TOP MCQs on Fibonacci using Recursion and Answers


2. 250+ TOP MCQs on Sum of n Natural Numbers using Recursion and Answers
3. 250+ TOP MCQs on Recursion and Answers
4. 250+ TOP MCQs on Length of a String using Recursion and Answers
5. What is the data structures used to perform recursion?
6. 250+ TOP MCQs on Power of a Number using Recursion in Logn Time and Answers
7. 250+ TOP MCQs on Search an Element in an Array using Recursion and Answers
8. 250+ TOP MCQs on Decimal to Binary Conversion using Recursion and Answers
9. 250+ TOP MCQs on Sum of Digits of a Number using Recursion and Answers
10. 250+ TOP MCQs on Factorial using Recursion and Answers
11. 250+ TOP MCQs on Search an Element in an Array using Recursion and Answers
12. 250+ TOP MCQs on String Reversal using Recursion and Answers
13. 250+ TOP MCQs on Python Recursion and Answers
14. 250+ TOP MCQs on Length of a Linked List using Recursion and Answers
15. 250+ TOP MCQs on Search an Element in a Linked List using Recursion and Answers
16. 250+ TOP MCQs on Largest and Smallest Number in an Array using Recursion and Answers
17. 250+ TOP MCQs on Largest and Smallest Number in a Linked List using Recursion and Answers
18. 250+ TOP MCQs on Recursion and Answers
19. 250+ TOP MCQs on Recursion and Answers
20. 250+ TOP MCQs on While Loops and Answers
LEAVE A REPLY

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Post Comment

Engineering 2023 , FAQs Interview Questions , Theme by Engineering|| Privacy Policy|| Terms and Conditions|| ABOUT US|| Contact US||
Engineering interview questions,Mcqs,Objective Questions,Class Lecture Notes,Seminor topics,Lab Viva Pdf PPT Doc Book free download. Most Asked Technical Basic CIVIL | Mechanical
| CSE | EEE | ECE | IT | Chemical | Medical MBBS Jobs Online Quiz Tests for Freshers Experienced .

You might also like