Line 5
// function main begins program execution
is another single-line comment indicating that program execution begins at the next line.
Line 6
int main()
is a part of every C++ program. The parentheses after main
indicate that main is a program building block called a function. C++ programs typically consist of one or more functions and classes (as you’ll learn in Chapter 3). Exactly one function in every program must be named main
. Figure 2.1 contains only one function. C++ programs begin executing at function main
, even if main
is not the first function defined in the program. The keyword int
to the left of main
indicates that main
returns an integer value. The complete list of C++ keywords can be found in Fig. 4.2. We’ll say more about return a value when we demonstrate how to create your own functions in Section 3.3. For now, simply include the keyword int
to the left of main
in each of your programs.
The left brace, {, (line 7) must begin the body of every function. A corresponding right brace, }, (line 11) must end each function’s body.