Example 1 — Declare above main, define below
The declaration lets main call functions defined later.
#include <stdio.h>
int max_of(int a, int b);
int min_of(int, int);
int main(void) {
printf("max: %d\n", max_of(8, 3));
printf("min: %d\n", min_of(8, 3));
return 0;
}
int max_of(int a, int b) { return a > b ? a : b; }
int min_of(int a, int b) { return a < b ? a : b; } How It Works
min_of(int, int);omits parameter names, which is allowed in declarations.- Definitions appear after
mainbut the declarations make the calls legal. - Each function is defined exactly once.
