Chapter 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 chapter, 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 that the program does what we want it to do?). In the following sections, 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:

2.2. Declarations

2.3. Definitions

2.4. Statements

2.4.1. Iteration

2.4.2. Function calls

2.4.3. Function return

Summary

sitemap