Wednesday, 24 August 2016

First Program in C++



Program:


#include<iostream.h>
void main()
{
cout<<"Hello world";   //For showing output
}


#inlcude<iostream.h> : This is a header file. Included for the input and output which is needed in every program. 

void main(): this is the main function where the program is executing. It starts with { and ends with }. All statements written within these braces are included in program. It has 'void' return type because our main function is returning no values.

cout : It is used for showing the output ("Hello World" in the above example).

// : This is called a comment and it doesn't affect the program. It's used for keeping tracks of the things as you know large programs becomes complicated, so we need comments. You can also use /* */. Anything written between these are also considered as comments and these can be used for multiple lines comments.
Example:  /*  This is a
                        sample for
                        multiple line comments*/

So this was a simple C++ program.

No comments:

Post a Comment