A function may call itself. Factorial is n * fact(n-1), and fact(1) is 1 so the chain stops.
Factorial n! means n × (n-1) × … × 1, and 1! (and 0!) is 1. A recursive function asks a smaller clone of itself for help, then multiplies. fact(4) is 24.
4*fact(3)
3*fact(2)
1
unwind
Each step highlights the matching C line. Program output appears only when a line that prints actually runs.
Five questions. Pick one answer each, then Check answers. The correct choice turns green.
1. fact(4) is:
4*3*2*1.
2. The base case is:
Stops recursion.
3. Without a base case:
Must stop.
4. An iterative kind of factorial uses:
Same result, no stack growth.
5. fact(1) returns 1 so that:
Bottom of the chain.