C Program Structure
Figure 1-1
illustrates the structure of a C
program. The program shown consists of the functions
main()
and
showPage()
, and prints the beginning of a text
file to be specified on the command line when the program is started.
The
statements
that make up the functions, together with the necessary declarations
and preprocessing directives, form the source
code of a C program. For small programs, the source code
is written in a single source
file
. Larger C programs consist of several
source files, which can be edited and compiled separately. Each such
source file contains functions that belong to a logical unit, such as
functions for output to a terminal, for example. Information that is
needed in several source files, such as declarations, is placed in
header files.
These can then be included in each source file via the
#include
directive.
Source files have names ending in .c; header files have names ending in .h. A source file together with the header files included in it is called a translation unit .
There is no prescribed order in which functions must be defined. The
function showPage()
in Figure 1-1 could also be placed before the function
main()
. A function cannot be defined within
another function, however.
The compiler processes each source file in sequence and decomposes its contents into tokens , such as function names and operators. ...
Get C Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.