Namespaces
Variants
Actions

User:Legalize/Learn C++/Simplest Program

From cppreference.com

The Simplest C++ Program

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

int main()
{
    return 0;
}

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 main.

Every function must have a return type and declare the number and types of arguments passed to the function. The keyword int designates a signed integer type as the return value of the function main. The parenthesis following the function name main 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 { and } characters enclose the body of the function main that defines its behavior. When main 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 main contains a single statement terminated with a semi-colon (;). Every statement in C++ is terminated by a semi-colon. The return statement returns control to the caller of a function. If the function returns a value, the return statement must provide the return value of the function. main returns a signed integer and the return statement provides the expression 0 as the return value. The expression 0 is an example of an integer literal.

Let's recap the concepts illustrated in this small example: