Monday, June 11, 2012

C++ For Beginner - Dissection of the Program

1. #include<iostream.h>

The #include directive is a special type of instruction called a preprocessor directive. This is an instruction to the compiler to take the entire file iostream.h andplace it in the program.

The preprocessor is a program that modifies your source file prior to compilation. Common preprocessor directives are #include which is used to include additional code into your source file, #define, which is used to define a constant and #if/#endif, which can be used to conditional determine which parts of your code will compiled.

2. // Prints "Welcome to Turbo C++" on screen

The next line in our program  is a comment. Comments are explanations or annotations that are include in a program for documentation and clarification purposes.

The compiler does not generate machine code for comments. Any line of  text placed after the symbols // or between slash asterisk-asterisk slash /* */ is ignored by the compiler.


There are two wayws to specify a comment in Turbo C++:
  1. In standar C++, we can use /* and */ to surround comments.
  2. Certain C++ compilers permit // to begin comment lines.
Here is an example of placing comments in Turbo C++ programming



























3. int main ( )

This is the function prototype statement for the main function. This is required in every C++ program. Usually, when we start a program, DOS load it and transfers control to it. In orfer to do that, DOS has to know where to enter a program and start executing. Thats what the term int main ( ) if for, DOS looks for the part of the program labeled int main ( ) and start there. In other words, int main ( ) is the label that tags the beginning of the program.

4. { }

This encloses the body of the program.
Usually the curly braces enclose more program line, such as this the ;

#include<iostream.h>
/* The required header file for cout<<( ) is iostream.h
    This is Prints
    The word Welcome Turbo C++ on the screen */
 int main ()       //The main function
{
     cout<<"Welcome Turbo C++" ;
     return 0 ;
}


Statements like this end with a semicolon ( ; ), referred to as statement terminator. Each action in c++ is a statement, and a semicolon must end each one.

5. cout<<

cout (pronounced as "see-out") is used to write output to the standard output, usually the screen. cout means console output.

cout<< "Wecome Turbo C++"; is a sample C++ statement. The output operator << directs the values to the cout output stream. The output stream cout is used with insertion operators << in the syntax.

Because cout<< is the normal way of printing on the screen in C++, it's pretty powerful. We are not limited to just printing words; we also have control over the way we print those words on the screen. For example, we can place the character \n in the character string like this \n

#include<iostream.h>
 int main ()      
{
     cout<<"Welcome Turbo C++ \n ";
     return 0;
}

6. return 0;

This causes the main to return a zero value indicating to the operating system that the program terminated normally.

No comments:

Post a Comment