Structure of C++ Program

A C++ Program includes a set of commands running to obtain the desired result.

Every program in C++ is structured in an organized and specific way. It starts from importing header files at the start which is followed by the main function containing the code in its body.

Structure of C++ Program

Structure of C++ Program

Header Files

Through header files, we can include multiple libraries in c++ for our use. For including a header file you need to write  # include <name_of_header_file>. Some important header files are:

1. iostream: This library helps in taking input or giving an output of different values.

2. vector: This library is used to include vectors. Vectors are kind of dynamic arrays so they can resize themselves according to the number of elements.

3. algorithm: This library provides some of the important algorithmic functions like sorting, reversing, finding the maximum or minimum element.


It helps in combining objects, functions inside the same name. The most common namespace is std and whenever while declaring it we need to write the ‘namespace’ keyword.

Main Function

The point from which the program is read by the compiler is the start of the main function. This is the only function called by your system after clicking on run and all the other functions are called inside it (if they are present).

The code that needs to be executed is written inside the main function’s body. The execution stops when the return line is reached.

Leave a Comment

Your email address will not be published. Required fields are marked *