A0

Labels

Operation of Hello World c++

 

[C++ is case sensitive language means if we will use upper case letter at the place of lower letter in the syntax then program will generate the error.] 

Here is the article related to c++ programming. Firstly we will check the simple Hello World program and then break that program into pieces and then check the every line and its use in the program

       
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World"<<endl;
return 0;

This is the program which will display the message "Hello World". Now we will break this program into pieces.

1) #include<iostream>

This is called header file in c++. We uses different kind of header files to access the different functionality of c++. This is like the key to access the treasure. In simple words if we want to access the specific file then we uses header file. In the above program I used iostream header file which is uses to take input or display the data or for basic functionalities such as to break line etc.


2) Using namespace std;

Actually the complete syntax of c++ is like

 "std::cout<<"Hello World"<<std::endl;"
 (in this way use std:: with every object used from specific header file)

 this syntax will become little bit difficult to implement therefore, we use using namespace std and this will automatically apply the std with every object of header file and in this way it will become more easy to use. 

Note:  

do you focus here at the end of the line I used a semi column(;) this we use to tell the compiler that we had end the line.


3) int main()

we can also use void at the place of int. Actually, we use main as a driver of the program like a car. Main should be compulsory in a program because without main program cannot run also every program always start from main. Moreover, this is more like a function which should be compulsory in a program. May be, in this stage you are not familiar with functions so, don't worry we will learn in our next lectures.

Note: After using int main() we will also define the scope for main by using the bracket({). If you don't know how to define the scope then answer is you can define scope like this { here you can write the program part}.

4) cout<<"Hello World"<<endl;

This is the main line to display the hello world as a output. Here I used cout and endl. cout is uses to display the data and after writing cout we need to use stream out operator(<<) and then use "Write string or message here" and then again stream out operator(<<) and then I used the endl to break the line. In this way I display the message as a output.


5) return 0;

We use return 0 when our main is of int type because int always return an integer at the end of the function. But if we will use void as the return type of main then it will return nothing at the end of the function.


In this way program works here. Now, you can try different experiments for this program to understand the behavior.