General Structure of C++ program


General Structure of C++ program


A C++ program can be developed from a general structure.
The general structure of C++ is same as of C language.

The general structure is divided into different sections :

1. Documentation Section

2. Preprocessor directives or C++ preprocessor
-Link section
-Definition Section

3. Global Declaration Section

4. Main C++ program function called void main()

5. Begining of the program by using{
-Local declaration or local variable declration
-Function declaration
-Executable part

6.End of the program using }

7. Sub-program section having user-defined functions

Function definition 1

---------------------

---------------------

Function definition n



Documentation section :

It consists of set of comment lines which include name of a program, author name, creation date and other information. The comments start with //(single line) or /*------*/(multi line).
The comments can be single line or multi line. We will discuss them in details later.
Eg: //Text line

Links Section :

It is used to link the required system libraries or header files to execute a program.

For Example #include < iostream.h > , # include < conio.h > etc.

Note : # symbol tells "link to" or "address to".

Definition Section :

It is used to define or set values to variables. That is macros.

Example : #define PI 3.14

Global variable declaration Section :

It is used to declare global or public variable.

In some programs we use function sub-programs. So we want to declare some variables in the
main program as well as in the function sub program having same name. This is the duplicacy
in defining the variables. So we take common variabl declaration above the main program
which is called global variable declarations.

void main() :

Used to start of actual C program. It includes two parts as declaration part and
executable part.

Variable declaration section :

Used to declare private variable or local variables.

Function declaration section :

Used to declare functions of program from which we get required output.

Executable statements :

Executable statements are provided.

Function definition section :

Used to define functions which are to be called from main(). We will discuss about functions
in detail.



     Prev                                                   NEXT

1 comments:

Nikola Anđelić said...

Nice post and very helpful. I also have a blog about c++ tutorials. If you want to see it please visit:
http://megacplusplustutorials.blogspot.com

Post a Comment