C++ tutorial 1- print hello world

Danoja Dias
Break the Loop
Published in
2 min readFeb 27, 2019

Wanna learn c++ from the scratch ? Here you will be learning how to write a very simple program printing hello world in c++. Remember if you get the basics of this programming language it will be so easier for you to understand the rest

Printing Hello World in c++

Run the above code and see the results. I’ll go through each and every line of this code. Then you can understand the meaning of this.

#include <iostream>

Here #include is called a Preprocessor directive and this is used to load files. What this does is similar to all the text in iostream.h file is copied and pasted into your file at this line.

In simple words we are loading iostream file here to use more functionalities that are already defined in this header file. This file includes the code for input and output operations that we need to print to the screen. We will talk about more on header files later.

using namespace std;

Here the std is an abbreviation for standard. This line of code means that we are using all the things defined in this standard namespace.

int main() 
{
cout << "Hello World" << endl;
return 0;
}

This is a function that is named main. We can have many functions as we want having various names. So how does the computer knows where to begin. That is where the main function comes into the picture. The computer knows the program should begin with the function named main.

int is the return value type of the function. This means that we return a value of integer. Within the next curly brackets, the lines are called statements that are ended with semicolon.

Statements                        
cout << "Hello World" << endl;
return 0;

cout is a output stream object. we get this from iostream file we added at the beginning. endl is an abbreviation for end line. that means go for next line.

Next return statement. Here it return 0 which means this program run without any problem. If it is not 0, That means there are errors in this program.

This is the overall explanation about this program.

--

--

Danoja Dias
Break the Loop

ATL at Enactor Ltd | Former R&D Engineer at Synopsys Inc | Former Intern at WSO2 | BSc Computer Engineering | GSoC2016 | http://linkedin.com/in/danojadias