How To Write Hello World Program In C++ Programming Language
How To Write a Hello World Program In C++ Programming Language
In this post we will look at how a C++ program works. We will try make the example as simple as possible for the beginners so they can easily understand the basics of C++. We will write a simple C++ hello world program in C++ programming language which is considered as the very first program in almost every programming language.
A Brief Introduction to the C++ Programming Language
C++ is an object oriented programming language and it is an extension to C programming language. C++ is a general purpose programming language and it is also a case-sensitive language. C++ is very powerful programming language it has features of both low level and high level programming languages, and that is why it is called mid level programming language.
Hello World program in C++ programming language
Above is an example of a simple Hello World program in C++ programming language. Now let us look at the code, and I will take you through this code and explain each line of code step by step in an easy way so that beginners can understand it very easily.
Code Description
In the first two lines we used #include directive to include or give the reference of header files which are iostream and conio.h.
For now, consider these files as documents that we included in our C++ program, due to which we can use some functions and objects that are defined in these files.
These functions and objects include _getch() and cout which are defined in iostream and conio.h files.
In the third line, we used the using namespace std. This line indicates that we are using a namespace in this code which is named as std.
If we don't use or include std at the start of the code, then with every cout statement we have to write it like std::cout << "Hello World";
After that, we used the void main() function, which is the main part of our program. A C++ compiler always looks for this function with the name main(). This is the entry point for our C++ program.
cout<<"Hello world" is used to print a Hello World message to the console screen. With the help of the cout object, we can display output to the console screen.
And at last we used the _getch() function that holds the console screen and does not let it disappear after the successful execution of our program.
Congratulations, as always, we have implemented our first C++ program successfully.
Comments
Post a Comment