C++ Program Structure

In this tutorial you will learn about the C++ Program Structure and its application with practical example.

C++ Program Structure

In C++, like any other programming language we have a specification available for program structure, every C++ program is consist of following building blocks –

Table Of Contents

cpp-program-structure

Documentation Section :- Documentation section is generally meant include set of comments, that is used to provide the information about the program written like name of a program, utility of program, date of creation, date of last modification ,author name, licensing or copyrights information and any other information that programmer wish to put for the references.

Example:-

Preprocessor Statements:- This is the section where we write all of the preprocessor directive statements, preprocessor statement usually with begins with a pound (#) symbol. Preprocessor statements are processed first when the compilation of the program begins. Preprocessor statements such #include tells compiler to include header files and #define directive is used to define constants prior to compilation of the program. Preprocessor statements are further categories as below –

Link Preprocessor :- These preprocessor directive tell the compiler to link the functions from system library.

Example:

Definition Preprocessor :- This the section where we define all our symbolic constant we gonna use in our program.

Example:

Global Declarations :- This is the section where all the global declaration comes. All of the variables, structures, classed and function defined or declared outside the main function are treated as global.

Class Definition :- The classes are used to map real world entities into programming. The Classes are the key building block of any C++ program. A C++ program may include several class definitions. This is the section where we define all of our classes.

Main Method Definition :- This is the most vital part of each and every C++ program, it is mandatory for C++ program to have a main() method definition. There can be only one main() method in C++ program. The execution of a C++ program starts with the main() method. The C++ program can not be executed without the main() method. The main() method is responsible for the execution of all the user defined statement, functions and library functions. The main() method further structured into – variable declaration, function declaration and user defined executable statements.

User defined functions :- This is the section of where we put all the user defined functions created to perform a specific task. A user defined function must be defined before use it. User defined function can written before or immediately after the main ( ) function and called inside the main ( ) function.

In this tutorial we have learn about the C++ Program Structure and its application with practical example. I hope you will like this tutorial.