Recursion splits a problem into smaller copies of itself. Each call gets its own frame on the stack until the base case says stop.
1 The Big Idea
A recursive function calls itself on a smaller input until a base case stops the chain.
2 Base Case
The condition that ends the recursion — without it, the stack overflows and the program crashes.
3 Recursive Case
The branch that does one small piece of work and hands the rest to another call.
4 The Call Stack
Every call gets its own frame with its own n — frames stack up, then pop as answers return.
5 inline (C99)
Small helpers can be marked inline — a hint asking the compiler to paste the body at each call for speed.
A function that calls itself
The Big Idea1A recursive function calls itself on a smaller input until a base case stops the chain. Base Case2The condition that ends the recursion — without it, the stack overflows and the program crashes.
Recursive Case3The branch that does one small piece of work and hands the rest to another call. The Call Stack4Every call gets its own frame with its own n — frames stack up, then pop as answers return. inline (C99)5Small helpers can be marked inline — a hint asking the compiler to paste the body at each call for speed. 5 building blocks make up A function that calls itself
Each call asks the same question: is this the base case, or do I call myself again?
process decision input / output start / end Two programs, two tabs — watch factorial print as its frames unwind, then trace the two-way fork of fibonacci.
preprocessThe preprocessor pastes in stdio.h.
Memory
no variables yet — press play
Console
output appears as the program runs…
Every call pushes a frame; every return pops one. Drag to orbit while the script plays.
Drag to orbit the scene. Press Play to watch memory in action.
Fibonacci forks twice per call — what does fib(5) add up to?
Your predicted output — one line per console line
Hint: Base cases return 1 — build upward: fib(3) = 2, fib(4) = 3, fib(5) = 3 + 2 = 5.
Click a term, then click its meaning to lock the pair.
5 conceptsTap a card to expand ?base casedrops into place
?recursive casedrops into place
?call stackdrops into place
?stack overflowdrops into place
?inlinedrops into place
01Every recursive function needs a base case — or the stack never stops growing.
02Each call gets its own frame: its own n, its own locals.
03Calls stack up on the way down and resolve on the way back up.
04Fibonacci calls itself twice per level — the call tree grows fast.
05inline is a C99 hint asking the compiler to paste small function bodies at the call site.