1. What is recursion in C++?
(A) Function calling another function
(B) Function calling itself directly or indirectly
(C) Loop repeating a block
(D) Function returning another function
2. What is essential for every recursive function?
(A) A loop
(B) A base condition
(C) A static variable
(D) A return value
3. What will the following code print?
int fun(int n) { if(n == 0) return 0; else return n + fun(n – 1); }
int main() { cout << fun(3); }
(A) 3
(B) 0
(C) 7
(D) 6
4. Recursion terminates when:
(A) Base condition is met
(B) Function returns void
(C) Function has parameters
(D) Stack overflows
5. What is the output of this code?
void print(int n) { if(n == 0) return; cout << n << " "; print(n – 1); }
int main() { print(3); }
(A) 1 2 3
(B) 3
(C) 3 2 1
(D) Error
6. Which of the following correctly describes recursion?
(A) A repeated function call chain
(B) Function calling itself until a condition is false
(C) Function running infinitely
(D) Function skipping return
7. What will this code print?
int fact(int n) { if(n == 1) return 1; return n * fact(n – 1); }
int main() { cout << fact(4); }
(A) 24
(B) 10
(C) 6
(D) Error
8. Recursive functions use which data structure internally?
(A) Queue
(B) Stack
(C) Array
(D) Linked list
9. What happens if base condition is missing in recursion?
(A) Function executes once
(B) Compiler gives error
(C) Infinite recursion leading to stack overflow
(D) Program exits normally
10. What is the output of this code?
void test(int n) { if(n == 0) return; test(n – 1); cout << n; }
int main() { test(3); }
(A) 321
(B) Error
(C) 12
(D) 123
11. What is recursion that calls itself again before completing one call known as?
(A) Tail recursion
(B) Head recursion
(C) Nested recursion
(D) Infinite recursion
12. What will the code print?
void fun(int n) { if(n == 0) return; cout << n << " "; fun(n – 1); cout << n << " "; }
int main() { fun(2); }
(A) 2 1
(B) 2 1 2
(C) 1 2 1
(D) 2
13. What is the output of this code?
int fun(int n) { if(n <= 1) return 1; return fun(n – 1) + fun(n – 2); }
int main() { cout << fun(4); }
(A) 5
(B) 3
(C) 4
(D) 6
14. What type of recursion is this?
int fun(int n) { if(n == 0) return; fun(n – 1); }
(A) Tail recursion
(B) Nested recursion
(C) Indirect recursion
(D) Head recursion
15. What will be printed?
void fun(int n) { if(n == 0) return; cout << n; fun(n – 1); }
int main() { fun(3); }
(A) 321
(B) 123
(C) 3
(D) Error
16. Which of the following recursion types call itself at the end of the function?
(A) Tail recursion
(B) Head recursion
(C) Indirect recursion
(D) Binary recursion
17. What is the output of this program?
void show(int n) { if(n <= 0) return; show(n – 1); cout << n; }
int main() { show(3); }
(A) 12
(B) 321
(C) 123
(D) 23
18. Which recursion is faster in execution?
(A) Tail recursion
(B) Head recursion
(C) Binary recursion
(D) None
19. What happens when recursion depth becomes too large?
(A) Stack overflow occurs
(B) Queue overflow occurs
(C) Compilation error
(D) Function terminates early
20. What is the output?
int sum(int n) { if(n == 0) return 0; return n + sum(n – 1); }
int main() { cout << sum(5); }
(A) 10
(B) 15
(C) 5
(D) Error
21. In recursion, each function call is stored in:
(A) Code segment
(B) Heap memory
(C) Stack frame
(D) Register
22. Which of the following is an example of indirect recursion?
(A) A() calls A()
(B) A() calls B(), and B() calls A()
(C) A() calls itself twice
(D) A() calls no function
23. What is the output?
int fun(int n) { if(n <= 1) return 1; return n * fun(n – 1); }
int main() { cout << fun(3); }
(A) 6
(B) 9
(C) 3
(D) 1
24. Recursion can be replaced by:
(A) Pointers
(B) Arrays
(C) Templates
(D) Iteration using loops
25. What will this code output?
void print(int n) { if(n == 0) return; cout << n; print(n – 1); }
int main() { print(4); }
(A) 4321
(B) 1234
(C) 4
(D) Error
26. What is the output?
void rec(int n) { if(n < 1) return; rec(n – 1); cout << n; }
int main() { rec(4); }
(A) 4321
(B) Error
(C) 12
(D) 1234
27. Which of the following is an advantage of recursion?
(A) Reduces code complexity for problems like factorial, Fibonacci
(B) Increases memory efficiency
(C) Increases program speed
(D) Makes debugging easy
28. Which of the following is a disadvantage of recursion?
(A) Requires less memory
(B) Harder to understand
(C) Takes more memory and time
(D) Doesn’t terminate
29. What is the output?
void test(int n) { if(n == 0) return; cout << "*"; test(n – 1); }
int main() { test(3); }
(A) *
(B) ***
(C) **
(D) Error
30. What kind of recursion occurs when a function calls itself more than once?
(A) Linear recursion
(B) Tree recursion
(C) Nested recursion
(D) Tail recursion