C Programming Multiple Choice Question - Recursion
This section focuses on the "Recursion" in C programming. These Multiple Choice Questions (MCQ) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. The process in which a function calls itself directly or indirectly is called?
A. Recursion
B. Type Conversions
C. Constant
D. Abstract Classes
View Answer
Ans : A
Explanation: The process in which a function calls itself directly or indirectly is called recursion
2. A function fun is called __________ if it calls the same function fun.
A. indirect recursive
B. direct recursive
C. Both A and B
D. None of the above
View Answer
Ans : B
Explanation: A function fun is called direct recursive if it calls the same function fun.
3. Which of the following is not an example of recursion?
A. Towers of Hanoi (TOH)
B. DFS
C. Inorder Tree Traversals
D. SFS
View Answer
Ans : D
Explanation: SFS is not an example of recursion.
4. When any function is called from main(), the memory is allocated to it on the stack.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not Say
View Answer
Ans : A
Explanation: The above statement is true statement.
5. Iteration requires more system memory than recursion.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not Say
View Answer
Ans : B
Explanation: Recursion requires more system memory than iteration due to the maintenance of stack.
6. 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.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not Say
View Answer
Ans : A
Explanation: 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.
7. The data structure used to implement recursive function calls _____________
A. Array
B. Linked List
C. Binary tree
D. Stack
View Answer
Ans : D
Explanation: The compiler uses the data type stack for implementing normal as well as recursive function calls.
8. What will be output for the following code?
#include <stdio.h>
main()
{
int num=5;
int fun(int num);
printf(""%d"",fun(num));
}
int fun(int num)
{
if(num>0)
return(num+fun(num-2));
}
A. 6
B. 7
C. 8
D. 9
View Answer
Ans : C
Explanation: The output for the following code : 8
9. What will be output for the following code?
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
View Answer
Ans : B
Explanation: 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.
10. Which of the following is true about recursion?
A. Recursion provides a clean and simple way to write code.
B. The recursive program has less space requirements than iterative program
C. The principle of stack is FIFO
D. All of the above
View Answer
Ans : A
Explanation: Recursion provides a clean and simple way to write code is true about recursion.
Discussion
Anjali Shinde
main()
{
int num=5;
int fun(int num);
printf(""%d"",fun(num));
}
int fun(int num)
{
if(num>0)
return(num+fun(num-2));
}
how answer is 8?