Structure of a C++ Program | Components of C++ Program

Structure of C++ Program

Structure of a C++ Program | Components of C++ Program

Structure of a C++ Program contains different parts as follows

  1. Documentation Section
  2. Link Section
  3. Definition Section
  4. Global Declaration Section
  5. main() function Section
  6. Subprogram Section [User Defined Function Section]

Documentation Section

In this section we can specify the name of program along with details of developer and other details as per requirement. We can use comments for documentation section.


/* Program to show the use of cout<< statement*/

Comments start from /* and end with */ 

Link Section

This section includes header files and performs conditional compilation of a C++program. This section also links the program with library of C++.

Example:  #include<iostream>

We need to include iostream header file in a program if we want to use cout, cin and other input output operations in a C++ program .

Definition Section

This section can be used to define the macros and symbolic constants in a C++ program.


i. #define  PI  3.141

Symbolic constant PI has been declared containing value 3.141. Its value can’t be changed during program execution. 

ii. #define perimeter(r) 2*3.141*r

Macro with name perimeter has been defined in this example . It contains one argument. When this macro is invoked it will return perimeter of circle depending upon the value of argument r passed to it. 

Global Declaration Section

We can declare global variables and user defined types like structures and classes. in this section.  Global variables can be accessed and used by multiple functions in a program. Any changes made to them are available in entire program.

main() Function Section

Every program has a main() function. This function has two parts.

– Declaration Part: we can declare local variables here. They can be of different data types. Values of these variables can change and remain active till the end of main()  function.

– Executable Part : We write the C++ statements in this part. It can contain any number of executable statements of C language.

Subprogram Section

We can define  user defined functions in this section. These functions can be invoked by the main() as well as other functions. These functions can also be defined before main() function. 


Spread the love
Lesson tags: Components of C++ Program, Structure of a C++ Program
Back to: C++ Programming Notes
Spread the love