Dec 9, 2011

First C++ Program

First Program in C++

Header File & Comments

Before that i want to tell You Header File in Every Program is necessary like <iostream.h>. Header file provide us some built in function & you can comment in your program anywhere by using //(double backslash) - Its Single Line Comment and for multiple lines you can use we use 
/* .......................
...............................*/
Comments are used to know about what program is, what this function do & remember to our self which part work which functions & This comments does effect your Program . This is ignore by Compiler.



Lets Continue with your First Program


HELLO WORLD PROGRAM

#include<iostream.h> // #include for import header file
#include<conio.h>  /* This is used for built in function getch()
                                      later you will know about it */

int main()      //int is a integer datatype of main function
{                   // main function is necessary in all c++ programs
                    // { this show function starts
cout << "HELLO WORLD"; 
/* cout is a function by iostream.h and its print the output on a screen. << this symbol for output. Within Double Quote We can Write any Thing You wanna To Display On Screen. & Every Statement must end with Semi Colon(;). */
getch();

/* getch() function is provided by conio.h(header file) its used because after display 'hello world' it automatically exit instantaneous so prevent this we can use getch() it take user input to exit(any key to exit). */

return 0; //As main type is integer so it return something

} //at End Close Above Main Function & it's End of your program


Above Program Without Comments


#include<iostream.h>
#include<conio.h>
int main()
{
cout << "HELLO WORLD";
getch();

return 0;

}

OUTPUT//





0 comments:

Post a Comment