structure of a program in C++

In this page, we will discuss following structure of a program in C++ are follows,

Header file in C++

In C++, before making a program we include some system library file in the header of the program. these file are called header file. These files contain a lot of functions that have a code to perform a task. To use these functions in a program, we have to include their file (within which it define) in the program header.

Here is syntex to include a header file in the program.



here .h is a file extension.
Here are the names of some header files and the operations or tasks they perform.

Yes, it is possible that a function can be defined in more than one header file like exit () functions are defined in both header file stlib.h and process.h.

All these functions are used further in this tutorial.

cout statement / output statement in C++

cout is an output statement that is used to print a message or result on an output device (like monitor screen).


<< called output operator or insertion operator.

cin statement / input statement in C++

cin is an input statement that reads the value of a variable at run-time, when the program is executed, values are given by an Output device (such as keyboard).




In the variable, the store value is printed by the output statement (cout statement).


>operator called input operator or extraction operator

Simple structure of a c++ program

In C++, a program is divided into two part first called header- file and second void main(), within the main() function, the code is written. 

structure of a program in C++ contain three block, here is the diagram below,


Here is the program,


void main()
  cout<<"Hello world";
hello world


iostream.h and conio.h, both are header file.
void is a return type, in which main() is a function that is the starting point of a program. Here the void type data type indicates that main() fuction is not returning any value.
getch() is a fuction that holds the output screen.

thing to know

  • In C ++, both statements (cout, cin) are terminated by semicolon (;).
  • Both cout and cin are define under in iostream class so we have to declare their header file (iostream.h) before using them.
  • In cout statement, the message is written within double quotes, whereas in the cin statement double quotes are not used to read the value of any variable.

previous-a brief introduction about C++

next-Token and keyword