C++ Hello World Program

In this post, we will learn how to write a simple hello world program in C++.

C++ Hello World Program

C++ is a general purpose programming language that supports generic and object oriented programming. C++ is a superset of C language and all valid C programs are valid in C++ as well.

Hello, World is the most simple program used to understand the basic syntax of any programming language. That’s why we are writing this post to help newbie coders.

So, without further ado, let’s begin this tutorial.

C++ Hello World Program

// C++ Hello World Program
#include <iostream>
using namespace std;

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

Output

Hello, World!

How Does This Program Work ?

#include <iostream> – The #include tells the preprocessor to include header files in the program.

iostream is a header file which contains functions for input and output operations such as cin and cout.  

Using namespace std – std(short form of standard) is a namespace and cout is defined in this namespace. A namespace is a special area inside which something is stored.

Int main() – Every program in C++ should contain main() function. The curly braces mark the start and end of the function.

cout – It is used to display the output to the standard output device.

endl – It is used to insert a new line character and flushes the stream

return 0 – The return 0 is the “Exit Status”.  return is a keyword used to return some value from a function. It indicates that our program has been run successfully and we terminate our main function with this return statement. 

// – Used for Commenting in C++

Conclusion

I hope after going through this post, you understand how to print hello world using C++ Programming language.

If you have any doubt regarding the problem, feel free to contact us in the comment section. We will be delighted to help you.

Leave a Comment

Your email address will not be published. Required fields are marked *