Control Flow & Functions
Write reusable C functions with prototypes, branch with if/switch, and iterate cleanly with for and while loops.
What you'll learn
- Declare function prototypes before main() so the compiler validates calls
- Use if/else, switch, and for loops cleanly
- Understand pass-by-value behavior for primitive parameters
C reads source files top-to-bottom. Placing a function prototype (declaration) above main() lets the compiler check argument types even when the full implementation is placed below main().
Pass-by-Value by Default
When you pass an int to a C function, C copies the value. Modifying the parameter inside the function does not change the caller’s original variable (unless you pass a pointer, which we cover in Lesson 4).
Fill-in-the-Blank Exercise
Function Prototype & Return
Declare a function that returns the square of an integer.
square(int n) {
n * n;
}Interactive Code Lab
Sum 1..5 = 15
Check Your Understanding
1. Why do C programs declare function prototypes near the top of a file or in a .h header?
Finished this lesson?
Your progress is saved locally in your browser, no account needed.