Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Prototypes and Program Organization

โญ beginnerโณ 10 min read๐Ÿ“ Lesson 24 of 225

Declaration before use: why prototypes exist and how files are organized.

Declare before use

C reads top-down. Calling a function whose name the compiler hasn't seen yet is an error (in C23 and under GCC 14 with our flags):

int main(void) {
    return area(3, 4);        // ERROR: 'area' unknown here
}

int area(int w, int h) { return w * h; }

Fix with a prototype (declaration) โ€” signature only, no body:

int area(int w, int h);       // prototype

int main(void) { return area(3, 4); }   // OK now

int area(int w, int h) { return w * h; } // definition

The rule you'll actually use

In graded challenges, define helpers above main (or prototype them) so the compiler has seen every name before it compiles the caller.

Files (a taste)

Real projects put prototypes in .h headers and definitions in .c files โ€” module 18 builds that out. For now: one file, helpers first, main last.