In this C++ programming tutorial, we are going to write a simple C++ or CPP hello world program. This is a simple C++ or CPP program to print hello world.
To understand this, you should have basic knowledge of C++ Programming. Click here to access the C++ tutorial.
Headings of Contents
C++ Hello World Program
This is the first C++ program of our C++ programming tutorial series. In this c++ program, we will print a simple C++ program “hello world“.
This is a very simple program of C++ programming language. if is often used to introduce new programming language to the newbie programmers.
C++ Hello World Program:
Example
// This is simple C++ program
#include <iostream>
using namespace std;
int main() {
// Write C++ code here
cout << "Hello World!";
return 0;
}
Output:
Hello World!
Understand the Working Of Above Program:
- In the first line, we have written a simple line “This is a simple C++ program” after // symbol. That means this line refers to the comment in C++ programming. Comments are used to describe the code so that users can understand the code easily.
In the C++ program, Comments are completely ignored by the C++ compiler. - #include
The #include is a preprocessor directive that is used to include files in the C++ program. As you can see in the above C++ program, we have import iostream file by using #include preprocessor.
iostream file allows using of cout in the C++ Program.
- using namespace std
Namespaces in C++ is used to organize too many classes so that it can handle the application. - int main() {..}
A valid C++ program must have the main() function. The curly bracket indicates the start and end of the function.
- cout << “Hello world!”;
cout is used to print the string on the screen or print the value of the variable on the string. - return 0;
The return 0 statement in C++ program refers to the exit status of the program.
Note: In C++ programming, Semicolon ( ; ) is used to terminate the line.
Conclusion:
So That, In this tutorial you have learned how to print the hello world programs in C++. Hello World is a simple program to introduced C++ to newbie programmers. In a later C++ program example, we will see a more complex C++ program.
I hope this article will help you to understand how to write a simple C++ program. If you like this article, please comment and share it with your friends who want to learn C++ programming from scratch to advanced.
For More Information:- Click Here