Structure of a C++ Program

Structure of C++ program: In this section, we are going to learn regarding the structure of a C++ program with examples. Also, we have explained the terms used in the program.

Structure of a C++ program

Let us write the first program in C++. And now in detail regarding the structure of C++ program.


void main( ) {  
   cout << "This is my first C++ Programming.";   

Let us know in detail regarding the program and the terms used in it.


It includes the standard input and output library functions. And in C++ language we are having a different type of header files. But, in this program, we are using <iostream>.


It consists of console input and output library functions.  And the getch( ) function is used in conio.h file.

void main( )

As we all know that the main( ) function is the entry to any of the programming language. Besides that, the void( ) keyword defines that it returns no value.


In C++ programming Cout is used to print the data on the console. Whatever you write next to it will be printed on the console.


We are also having the cin>>, which is used for reading the input from the keyboard. And in is the predefined class of the istream class.

getch( )

The getch( ) function asks every single character. Until you press any key it blocks the screen.

Compile and Running the C program

We can compile and execute the program in two ways. They are as follows:

By using the menu

  • Click on the compile menu and then click on the submenu to compile the Program.
  • Then click on the run menu and then run submenu to run a C++ program.

By using shortcut

Press ctrl+f9 keys to compile and run directly. If you want to see the user screen anytime, then press alt+f5 keys.

If you want to get out from the console press ESC key.