Welcome to the Kuwait Linux User Group, thats dedicated to talk about Linux, BSD, and the use of open source specially for Kuwait community & others as well -- beside encouraging them to use it.
Follow Us:

August 27, 2004 04:34 PM EDT

Structure of a C++ program

Author: . 4495 Reads
  Print this page   Export to PDF format   Mail to a friend

// my first program in C++

#include <iostream.h>

int main () { cout << " Hello World "; return 0; }

// this my first program in C++

//: All the lines beginning with two slash signs (//) are considered comments.

#include <iostream.h>

#: Sentences that begin with a pound sign (#) are directives for the preprocessor. They are not executable code lines but indications for the compiler.

include: to include.


standard header file.

This specific file includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is used later in the program.

int main ( can include arguments ) { The content of the main function }

Beginning of the main function declaration (begin their execution)

All C++ programs have a main function

In C++ all functions are followed by a pair of parenthesis () that, optionally, can include arguments.

The content of the main function immediately follows its formal declaration and it is enclosed between curly brackets ({}).

cout << "Hello World";

cout the standard output stream in C++ (usually the screen).

cout is declared in the iostream.h header file.

(;) signifies the end of the instruction and must be included after every instruction in any C++ program.

return 0;

The return instruction causes the main ( ) function finish and return the code that the instruction is followed by, in this case 0.

This it is most usual way to terminate a program that has not found any errors during its execution.

C++ programs end with a sentence similar to this.


// This is my first C++ program

/* It's about a hello program

you know what I am saying? */

#include <iostream.h>

int main ()


cout << "Hello Aziz!"; // :)

cout << "How are you?";

return 0;



Copyright © by Q8linux
All rights reserved.

Category: C++
Tags: None
Bookmark: Share/Save/Bookmark

[ Go Back ]
Content ©


What's your Favorite Mail Server(smtp)?

Lotus Notes


Votes: 102
Comments: 69

Old Articles