1.1. Writing a Simple C++ Program

Every C++ program contains one or more functions, one of which must be named main . The operating system runs a C++ program by calling main. Here is a simple version of main that does nothing but return a value to the operating system:

int main(){    return 0;}

A function definition has four elements: a return type, a function name, a (possibly empty) parameter list enclosed in parentheses, and a function body. Although main is special in some ways, we define main the same way we define any other function.

In this example, main has an empty list of parameters (shown by the () with nothing inside). § 6.2.5 (p. 218) will discuss the other parameter types that we can define for main.

The main function is required ...

Get C++ Primer, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.