Example 1 — Prototype for a function defined later
The call compiles cleanly because the prototype comes first.
#include <stdio.h>
int cube(int n);
int main(void) {
printf("cube(3) = %d\n", cube(3));
return 0;
}
int cube(int n) {
return n * n * n;
} How It Works
- The prototype appears before
main. - The compiler checks
cube(3)againstint cube(int n). - The definition can live anywhere later, or in another file.
