Example 1 — Main plus a helper function
Declare a function above main, call it, and define it below.
#include <stdio.h>
int square(int n);
int main(void) {
int x = 5;
printf("%d squared is %d\n", x, square(x));
return 0;
}
int square(int n) {
return n * n;
} How It Works
#include <stdio.h>makesprintfavailable.- The prototype
int square(int n);letsmaincall the function before it is defined. mainruns first, callssquare(5), and prints the result.return 0;reports success to the operating system.
