< previous page page_49 next page >

Page 49
0049-01.gif
The main function begins with the word int, followed by the word main and then left and right parentheses. This first line of the function is the heading. After the heading, the left brace signals the start of the statements in the function (its body). The shading and the three dots indicate that the function body consists of zero or more statements. (In this diagram we have placed the three dots vertically to suggest that statements usually are arranged vertically, one above the next.) Finally, the right brace indicates the end of the function.
In principle, the syntax template allows the function body to have no statements at all. In practice, however, the body should include a return statement because the word int in the function heading states that main returns an integer value. Thus, the shortest C++ program is
int main()
{
    return 0;
}
As you might guess, this program does absolutely nothing useful when executed!
As we introduce C++ language constructs throughout the book, we use syntax templates to display the proper syntax. In Appendix D, you will find these syntax templates gathered into one central location.
When you finish this chapter, you will know enough about the syntax and semantics of statements in C++ to write programs that perform calculations and print the results. But before we can talk about writing statements, we first must look at how names are written in C++ and at some of the elements of a program.
Naming Program Elements: Identifiers
Identifiers are used in C++ to name things. Identifiers are made up of letters (A-Z, a-z), digits (09), and the underscore character ( _ ), but must begin with a letter or underscore.

 
< previous page page_49 next page >