The Structure of a Simple Program

Now that you've seen a specific example, you are ready for a few general rules about C programs. A program consists of a collection of one or more functions, one of which must be called main(). The description of a function consists of a header and a body. The header contains preprocessor statements, such as #include, and the function name. You can recognize a function name by the parentheses, which may be empty. The body is enclosed by braces ({}) and consists of a series of statements, each terminated by a semicolon (see Figure 2.4). The example in this chapter had a declaration statement, announcing the name and type of variable being used. Then it had an assignment statement giving the variable a value. Next, ...

Get C Primer Plus, Fourth Edition 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.