User:Legalize/Learn C++/Simplest Program

= The Simplest C++ Program =

Here is the smallest valid C++ program that you can write:

This program hardly does anything at all, but it illustrates a few things.

Every program must somehow indicate where it should start. This is called the entry point and all C++ programs start execution with a function called cpp/language/main_function.

Every function must have a return type and declare the number and types of arguments passed to the function. The keyword cpp/language/types designates a signed integer type as the return value of the function. The parenthesis following the function name declares the number and type of arguments accepted by this function. In this case, there is nothing inside the parenthesis and the function takes no arguments.

The {{tt| { }} and {{tt| } }} characters enclose the body of the function that defines its behavior. When is executed, the statements in the body of the function definition are executed one at a time, starting at the open brace and continuing to the closing brace.

The definition of contains a single statement terminated with a semi-colon. Every statement in C++ is terminated by a semi-colon. The statement returns control to the caller of a function. If the function returns a value, the statement must provide the return value of the function. returns a signed integer and the statement provides the expression  as the return value. The expression is an example of an integer literal.

Let's recap the concepts illustrated in this small example:
 * the function
 * types and the type
 * functions
 * statements
 * expressions
 * integer literal expressions