IGDTUW 2026 Computer PYQ — What is the output of the following C program? #include <stdio.h>… | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
IGDTUW 2026 — Computer PYQ
IGDTUW | Computer | 2026
What is the output of the following C program?
#include <stdio.h>
void fun(int n) {
if (n == 0)
return;
printf("%d", n);
fun(n - 1);
}
int main() {
fun(4);
return 0;
}
Choose the correct answer:
A.
4321
(Correct Answer)
B.
43210
C.
1234
D.
Infinite Recursion
Correct Answer:
4321
Explanation
Step-by-Step Explanation:
Initial Function Call: The main function executes and invokes fun(4). Here, the parameter is:
n=4
Tracing the Recursive Calls: The function fun(int n) checks a base condition: if n==0, it terminates. Otherwise, it prints n and then calls itself with n−1 (tail recursion). Let's follow the execution sequence:
Execution of fun(4):
Condition 4==0 is false.
It prints the current value of n: 4.
It calls fun(4 - 1), which is fun(3).
Execution of fun(3):
Condition 3==0 is false.
It prints the current value of n: 3.
It calls fun(3 - 1), which is fun(2).
Execution of fun(2):
Condition 2==0 is false.
It prints the current value of n: 2.
It calls fun(2 - 1), which is fun(1).
Execution of fun(1):
Condition 1==0 is false.
It prints the current value of n: 1.
It calls fun(1 - 1), which is fun(0).
Execution of fun(0) [Base Case]:
Condition 0==0 evaluates to true.
The return; statement executes immediately without printing anything, shifting control back up the call stack.
Final Compiled Output: Since all numeric prints are written consecutively without any spaces or newline tokens, the output stream aggregates directly to:
4321
Explanation
Step-by-Step Explanation:
Initial Function Call: The main function executes and invokes fun(4). Here, the parameter is:
n=4
Tracing the Recursive Calls: The function fun(int n) checks a base condition: if n==0, it terminates. Otherwise, it prints n and then calls itself with n−1 (tail recursion). Let's follow the execution sequence:
Execution of fun(4):
Condition 4==0 is false.
It prints the current value of n: 4.
It calls fun(4 - 1), which is fun(3).
Execution of fun(3):
Condition 3==0 is false.
It prints the current value of n: 3.
It calls fun(3 - 1), which is fun(2).
Execution of fun(2):
Condition 2==0 is false.
It prints the current value of n: 2.
It calls fun(2 - 1), which is fun(1).
Execution of fun(1):
Condition 1==0 is false.
It prints the current value of n: 1.
It calls fun(1 - 1), which is fun(0).
Execution of fun(0) [Base Case]:
Condition 0==0 evaluates to true.
The return; statement executes immediately without printing anything, shifting control back up the call stack.
Final Compiled Output: Since all numeric prints are written consecutively without any spaces or newline tokens, the output stream aggregates directly to: