Home CPP Examples C++ “Hello World!” Program

C++ “Hello World!” Program

by anupmaurya
1 minutes read

Here is the simplest C++ program that will print the stringHello World, on the output. This is the first program told to a newbie while introducing them to programming language.

Let’s have a look at the program given below:

C++ “Hello World!” Program

// Simple C++ "Hello World" Program
 

#include <iostream>

using namespace std;
int main() {
    std::cout << "Hello World!"<<endl;
    return 0;
}

Output

Hello World!
  • In C++, any line starting with // is a comment. Comments are intended for the person reading the code to better understand the functionality of the program. It is completely ignored by the C++ compiler.
  • The iostream is a header file, stands for input/output stream, provides basic input/output services for the C++ program. Like in the above program, cout is used to put some content on the output screen. It is defined in iostream header file.
  • The following C++ statement:
using namespace std;

is used to provide standard (std) input/output namespace. That is, after including this statement, we do not need to write std:: before every cout and cin

  • The endl stands for end of line, used to break the line and start next thing from new line.
  • The return 0; statement is the “Exit status” of the program. In simple terms, the program ends with this statement.
  • The execution of code begins from the main() function. This function is mandatory. This is a valid C++ program that does nothing.

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.