The following example illustrates the structure of C++ program:

//hello.cpp (program name)

// this program display the message ‘welcome to WHO’


Void main()


Cout<<”welcome to WHO”; //message’ welcome to WHO’ is displayed


The components  of C++  program are:


Comments are used for better understanding of the program statements. The comment entries start with a // symbol and terminate at the end of the line.

Like in the above program—

//hello.cpp (program name)

// this program display the message ‘welcome to WHO’

In the above example the line message ‘welcome to WHO’ is displayed are comment lines and are ignored by the compiler.

  • #include directive

The #include directive instructs the compiler to include the contents of the file enclosed with angular brackets into the source file. In the program given above , the file iostream.h  is included in the source file hello.cpp

  • Function

All C++ programs comprise of one or more function. A function is identified by a function name and function body.

A function name is identified by a word followed by a parenthesis. In the above program, main() is a function name. All program must have function called main(). The execution of program start with a main(). The keyword void along with the function name signifies that the function does not return any value. Every function must have curly braces {} which delimit a block of  program statements.

  • Output using cout

The statement cout<<”welcome to WHO”;

Causes the text to be displayed on the screen.

Comments are closed.