Translation units and interfaces.
Understand separate compilation, linkage, prototypes, and command-line entry points.
The idea behind the syntax.
A translation unit is the source file after its included headers and preprocessing have been applied. Each translation unit is compiled separately, then the linker connects references to definitions. A function declaration in a header lets callers type-check a call; one matching function definition in a source file supplies the behavior. If declarations disagree across files, a program can compile in pieces yet fail to link or behave incorrectly.
Names with external linkage can refer to the same entity across translation units. Names with internal linkage, often marked static at file scope, stay local to one unit. This permits private helper functions and prevents accidental collisions. A public header should expose only what callers need; an internal implementation may change without requiring every caller to be rewritten.
What C guarantees.
main can receive command-line arguments through int argc and char *argv[]. argc counts strings including the program name, and argv[argc] is a null pointer. The text in argv is input from the execution environment, not automatically a valid integer or file path. Parsing and validation belong at the boundary before the rest of the program relies on those values.
The example keeps the interface in one source snippet but uses a function prototype before main to show the compiler's view of a separated declaration. The definition appears afterward. In a multi-file program, the prototype would normally live in a guarded header included by both caller and implementation. The function name and types must remain consistent on both sides.
Why the detail matters.
Separate compilation means one source file cannot rely on the compiler having read another source file's body. It relies on declarations. A prototype is therefore a promise about the call interface. If a header changes, all affected source files must be recompiled so their type checks use the new declaration. Build systems track this dependency because a stale object file can otherwise reflect an older interface than the source now describes.
External linkage is a naming contract at link time. A helper marked static at file scope is private to that translation unit, which reduces accidental name collisions and clarifies that callers should use the public wrapper instead. Command-line main adds another boundary: argc and argv provide strings from the host environment, not typed domain values. Parsing them once into a checked configuration keeps the rest of a multi-file program independent of raw argument text.
See the rule in context.
#include <stdio.h>
int square(int value);
int main(void) {
printf("Square: %d\n", square(6));
return 0;
}
int square(int value) {
return value * value;
}The prototype tells the compiler that square takes an int and returns an int before main calls it. main passes 6; the later definition multiplies the parameter by itself and returns 36. The linker can connect the call and definition because their name and compatible types agree. The output is Square: 36.
Where the rule stops.
A prototype is a contract, not an implementation. Declaring a function and never linking its definition leaves an unresolved symbol. Mismatched declarations across files are more dangerous than a simple missing symbol.
Keep this model.
A program's interface extends beyond its own source files to standard streams and the library. The next part treats input and output as operations that can fail and whose format strings or byte counts must match the data supplied.