Skip to content
Guest
Learn C · Course Syllabus Show lessons
C Foundations · 8 min read · Intermediate

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

Cfunctions.c
Expected OutputClick “Run Live” to compile with GCC 13 (C11)
Sum 1..5 = 15

Check Your Understanding

Score: 0 / 1

1. Why do C programs declare function prototypes near the top of a file or in a .h header?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind