C++ Learning Resource Network!

 C++ Tutorials  >  Introduction to C++  >  Structure Of C++ Program

The following example illustrate the structure of a C++ program:

 //Program 1.1
 //hello.cc(program name)
 //This program displays the message 'Hello World'
 void main()
        cout<<"Hello World"; // The message 'Hello World' is displayed

 This Program displays the message 'Hello World' on the screen.

 The Components of a 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. In Program 1.1,

 the lines

 //Program 1.1
 //hello.cc(program name)
 //This program displays the message 'Hello World'

 are comment lines.

 Multiple line comment entries can be included in a C++ program using the /* and the */ symbols.

 #include Directive

 The #include directive instructs the compiler to include the contents of the file enclosed within angular brackets into the source file. In Program 1.1, the file iostream.h is included in the source file hello.cc.

All c++ programs comprise one or more functions, which are a logical grouping of one or more statements. A function is identified by a function name and function body.

 A function name is identified by a word followed by parentheses. In Program 1.1, main() is a function name. All programs must have a function called main(). The execution of a program begins with the main() funtion. The keyword void along with the function name signifies that the function does not return any value.

 A function body is surrounded by curly braces {}. The braced delimit a block of program statements. Every function must have a pair of braces.

 Output Using cout

 The statement,

 cout<<"Hello World";

 causes the enclosed text to be displayed on the screen.



| Bookmark This Site |   | Links |   | Search |   | Submit |   | Contact |

  Copyright 2008 - 3008  CppTutor.com All rights reserved.