Saturday, 26 April 2014


The best way to under the structure of a program is by using an small and simple example.


// first program in C++ 

 #include <iostream> 
using namespace std;  
int main () 

 cout << "Hello World!"; 
 return 0; 


Hello World!  

Lets study each step in detail:

// my first program in C++ 

All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program

#include <iostream>

Hash sign (#) are directives for the preprocessor. The directive #include <iostream> tells the preprocessor to include the iostream standard file.
using namespace std;  It uses the standard library, and in fact it will be included in most of the source codes.

int main ()  This line corresponds to the beginning of the definition of the main function. The main function is the pointby where all C++ programs start their execution

cout << "Hello World!";
cout represents the standard output stream in C++

return 0;
The return statement causes the main function to finish.

No comments:

Post a Comment