A function is packaged work: give it a name, hand it inputs, get an answer back — reuse it forever.
1 Why functions
Write a block once, call it everywhere — no copy-paste, one place to fix bugs.
2 Parameters
The inputs a function receives: square(int n) gets n from the caller.
3 Return value
return sends the result back to the caller and ends the call immediately.
4 Overloading
Same name, different parameter lists — C++ picks the version by your arguments.
5 Modular thinking
Small single-job functions are easier to read, test and fix than one giant main.
Name a block of work
Why functions1Write a block once, call it everywhere — no copy-paste, one place to fix bugs. Parameters2The inputs a function receives: square(int n) gets n from the caller. Return value3return sends the result back to the caller and ends the call immediately. Overloading4Same name, different parameter lists — C++ picks the version by your arguments. Modular thinking5Small single-job functions are easier to read, test and fix than one giant main. 5 building blocks make up Name a block of work
Follow square(4): arguments travel in, a frame is pushed, the answer travels back, the frame pops.
process decision input / output start / end Two tabs: a first function returning a square, then two overloads sharing the name area.
preprocessThe preprocessor pastes in iostream for cout.
Memory
no variables yet — press play
Console
output appears as the program runs…
Each call pushes a frame on the stack; each return pops it. Drag to orbit, then play the script.
Drag to orbit the scene. Press Play to watch memory in action.
Click a term, then click its description to lock the pair.
5 conceptsTap a card to expand ?parameterdrops into place
?returndrops into place
?overloadingdrops into place
?voiddrops into place
?calldrops into place
Two calls, one name — which overload answers each?
Your predicted output — one line per console line
Hint: One int argument matches the first overload, so 3 + 1 prints. Two arguments match the second, so 3 * 4 prints.
01A function is packaged work: parameters in, return value out.
02Calling a function pushes a frame on the call stack; returning pops it.
03Overloads share a name — the argument list decides which one runs.
04Write small functions that do one job — that is modular programming.