In a program consisting of many different functions, it is often convenient to place
each function in an individual file, and then use the make utility to compile each file separately and
link them together to produce an executable.

There are a few common-sense rules
associated with multi-file programs. Since a given file is initially compiled separately from
the rest of the program, all symbolic constants which appear in that file must be defined at its
start. Likewise, all referenced library functions
must be accompanied by the appropriate references to header files.
Also, any referenced user-defined functions must have their prototypes at the start of the file.
Finally, all global variables used in the file must be declared at its start.
This
usually means that definitions for common symbolic constants, header files for common library functions,
prototypes for common user-defined functions, and
declarations for common global variables will appear in multiple files. Note that
a given global variable can only be initialized in one of its declaration statements,
which is regarded as the true declaration of that variable
[conventionally, the
true declaration appears in the file containing the function main()]. Indeed, the
other declarations, which we shall term definitions,
must be preceded by the keyword extern to distinguish them from the
true declaration.

As an example, let us take the program printfact4.c, listed previously, and break it up into
multiple files, each containing a single function. The files in question are
called main.c and factorial.c. The listings of
the two files which make up the program are as follows:

Note that all library functions and user-defined functions referenced in each file are
declared (either via a header file or a function prototype) at the start of that file.
Note, also, the distinction between the global variable declarations in the file
main.c and the global variable definitions in the file factorial.c.