Welcome to Kuwait Linux User Group - OpenSource free stuff

Search   in  

 Create an AccountHome | Gallery | Submit News | Your Account | Content | Topics | Top 10  

Modules
· Home
· Advertising
· Downloads
· FAQ
· Forums
· PHP-Nuke Tools
· Stories Archive
· Submit News
· Surveys
· Top 10
· Topics
· Tutorials
· Web Links
· Your Account

Search
Google
Web q8linux.net

  

Structure of a C++ program




// 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.

iostream.h:

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.

Example:

// 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;

}
 



aziz.

Copyright © by Kuwait Linux User Group - OpenSource free stuff All Rights Reserved.

Published on: 2004-08-27 (466 reads)

[ Go Back ]

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest ©2004-2008 by Q8linux.كويت لينكس
PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.03 Seconds