2 The principal structure of a program

 

This chapter covers

  • C grammar
  • Declaring identifiers
  • Defining objects
  • Instructing the compiler with statements

Compared to our little examples in the previous section, real programs will be more complicated and contain additional constructs, but their structure will be very similar. Listing 1.1 already has most of the structural elements of a C program.

There are two categories of aspects to consider in a C program: syntactical aspects (how do we specify the program so the compiler understands it?) and semantic aspects (what do we specify so the program does what we want it to do?). In the following subsections, we will introduce the syntactical aspects (grammar) and three different semantic aspects: declarative parts (what things are), definitions of objects (where things are), and statements (what things are supposed to do).

2.1 Grammar

Looking at its overall structure, we can see that a C program is composed of different types of text elements that are assembled in a kind of grammar. These elements are as follows:

  • Special words In listing 1.1, we used the following special words: 1
    #include int maybe_unused char void double for return

2.2 Declarations

2.3 Definitions

2.4 Statements

2.4.1 Iteration

2.4.2 Function calls

2.4.3 Function return

Summary