Introduction of C++ Language & C++ Hello World Program

SHARE THIS ARTICLE |

In the first tutorial of this website , I will give you introduction of C++ language and program to say ‘Hello World’.

Introduction of C++:

C++ is a powerful programming language. It was developed by Bjarne Stroustrup in 1980 at Bell Labs. Since it is a middle level language, so it have features of both high level and low level programming languages. C++ language has many features like Object Orientation, Machine independence and incredible speed. C++ is so powerful language that anything a computer is capable of doing can be done with C++. Following softwares are written using C or C++(although C++ was written in C language, but now C is is considered a subset of C++):Bjarne Stroustrup - founder of C++

  1. Major Operating Systems (Linux, Mac OS X, Windows)
  2. Amazing Games (World of Warcraft, Diablo series, StarCraft series etc)
  3. Console Games (Wii series, PlayStation series etc)
  4. Development Environments and Compilers (GNU C++, Visual Studio etc)
  5. Major Productivity Softwares (MS Office, Photoshop,AutoCAD etc)
  6. Major Web Browsers (Chrome, IE, Firefox, Opera)

Now you know that it is good to learn C++ but where to write C++ program? The simple answer to this question is an IDE like Dev C++.

DEV C++:

Integrated development Environment(IDE) is a user interface that allows the user to create c++ programs. There are many IDEs available for c++. I recommend you to use Dev C++ because you can write quality programs using Dev C++. All the code uploaded on this website is written using Dev C++. You can download this program by clicking following link.

Click Here to Download Dev C++

The installation process is quite easy. It just requires some clicks on ‘Next’ and ‘Finish’ buttons.

Say ‘Hello World’:

Now lets move to the second part of this tutorial. In this part we will write a program in Dev C++ which will print ‘Hello World’ on the screen. ‘Hello World’ is a good example program to learn the basic syntax of a new language.

What you have to do is to open up your Dev C++ IDE and press Ctrl+N to create a new file. Now write the code given below:

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

When you have done writing the program, press F11 to Compile & Execute your program. A pop-up window would be appeared asking you to save the program. Just select a place where you want to keep this program on hard disk and press Enter. Now your program would be executed means an output would be shown in Console window. Here is the output of our program:

C++ program to say Hello World

The text written below the line is just information from console window. Our code does only what is written above the line means ‘Hello World’.

How Program Works:

Our source code contains 6 lines. I will explain you line by line how these lines make a program to work.

Line 1:

#include<iostream>

First line of this program is starting with pound(#) sign. In C++, every line beginning with pound sign is used by the compiler’s pre-processor. In this case, the directive #include tells the compiler to include iostream file. Iostream is a header file of C++ and it contains the basic input/output function like cout, cin etc. These function are pre-defined in C++ and are kept in iostream file. We included this file so we can use those functions in our program.

Line 2:

using namespace std;

Namespaces provide a method for preventing name conflicts in programs. The line tells the compiler to use namespace named ‘std’. The ‘std’ namespace is special, it is short for the word ‘standard’. The built-in C++ library routines are kept in the standard namespace. So we used this line to specify that names used in this program ( like cout ) are defined in standard C++ libraries. Since these names are very often used, so you may find this line in every C++ program. Notice the semi-colon ( ; ) at the end of this line, it is used to terminate the C++ statement. It is very important so be careful about it.

Line 3:

int main(){

In C++, every program must have a main() function. The main function is the point where all C++ programs start their execution. The word main is followed by a pair of round brackets. Though these brackets are empty but they are necessary. Keyword int shows that function main()  returns a value whose data type is integer. At the last there is opening curly brace ( { )  which reveals that main() function is starting form this point and all the upcoming statements are considered the body of main() function until a closing curly brace ( } ) is not detected.

Line 4:

cout<<"Hello World";

To print something on the screen, we use a cout statement. cout is the short form of Console Output. This statement starts with keyword cout then the insertion operator  (<<) and finally the items to be displayed on the screen. In this case, we wrote ‘Hello World’ in double quotations. This statement will print ‘Hello World’ on the screen. Again semi-colon ( ; ) comes at the end of line to terminate cout statement.

Line 5:

return 0;

The last instruction of every program is return statement. The return statement with integer value 0 is used to indicate to the operating system that the program has terminated successfully.

Line 6:

}

In this line, we have only a closing curly brace. As I have told you that the body of main function starts from opening curly brace and ends with a closing curly brace. All the statements between this braces are considered the body of main function.

If you don’t want to write code yourself then you can Click Here to download Exercise Files.