• Have Any Question?
  • contact@eitworld.com

cpp basic syntax

structure of c++ program

Structure of a C++ program contains various sections. The general structure of any C++ program contains following section as given below:


  • Documentation:Documentation is an optional section. This is generally used to put comments for the program. Comments help to understand the programs in context of what we are developing in the program.
  • Header Files:This section includes header-files required by our C++ program. We can make our own header files and can use in the program.
  • Symbolic Constants, Global variable and functions:These sections are declared after the header files if required. Global variables can be used in the whole program and we can use functions in whole program after defining the code for the functions.
  • Class declaration:class is main building block of any C++ program. Class declaration contains the declaration of data members and functions. You will study the concept of class in later sections.
  • main() functions:main() function must be present in the every C++ program. Execution of all C++ program begins with the main() function.
  • A program that gives the idea of structure of a C++ program is given below. Don’t worry if you don’t understand it in this chapter you will study each section used in this program in later section.

C++ Program Structure:

/*This is comment: Demo Program for C++ Structure*/

/*Header file inclusion*/



/*global variable declaration*/

int x; float y; char z;/*global variables*/

void disp();/*global function declaration*/

/*class declaration*/

class demo



int x,y;/*data-member declaration*/


void input(int a, int b)/*member-function declaration*/

void show();


/*class declaration ends here*/

/*class-function definition*/

void demo::input(int a,int b)





/*class function definition*/

void demo::show()





/*main function definition*/

void main()


demo d1,d2;/*creating objects of class*/



int num;

show();/*local function call*/


/*global function definition*/

void show()


cout<<“in shown”;



Real Time Web Analytics