Wednesday, August 1, 2012

C++ Language TutoriaL

C++ Language TutoriaL


// my first program in C++  
This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not 
have any effect on the behavior of the program. The programmer can use them to include short 
explanations or observations within the source code itself. In this case, the line is a brief description of 
what our program is.  
#include <iostream>  
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines 
with expressions but indications for the compiler's preprocessor. In this case the directive #include 
<iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) 
includes the declarations of the basic standard input-output library in C++, and it is included because its 
functionality is going to be used later in the program.  
using namespace std;  
All the elements of the standard C++ library are declared within what is called a namespace, the 
namespace with the name std. So in order to access its functionality we declare with this expression that 
we will be using these entities. This line is very frequent in C++ programs that use the standard library, 
and in fact it will be included in most of the source codes included in these tutorials. 
int main ()  
This line corresponds to the beginning of the definition of the main function. The main function is the point 
by where all C++ programs start their execution, independently of its location within the source code. It 
does not matter whether there are other functions with other names defined before or after it - the 
instructions contained within this function's definition will always be the first ones to be executed in any 
C++ program. For that same reason, it is essential that all C++ programs have a main function.  
The word main is followed in the code by a pair of parentheses (()). That is because it is a function 



No comments:

Post a Comment