Site icon i2tutorials

CPP- Structure of C++ program

Structure of C++ program

 

 

It is common to organize a program into 3 files. Class declarations are placed in one header file and member function definitions move to another file.This approach allows the programmer to separate the abstract interface specification (class definition) and implementation details (member function definition). Finally, the main program that uses the class is put into a third file that “includes” the two previous files and any other required files.A typical program contains 4 sections, some of them(sections) are optional.

 

1) Include Files:

 

2) Class Declaration or Definition:

 

Syntax:

class <class name>
{
Variables declaration; // data members or member variables
Function declaration/definition; // called as member functions
}; // End of class

 

3) Class function definitions:

 

4) main( ) function:

All the C and C++ programs start execution from main( ) function.

 

Exit mobile version