C++ “Hello World!” Program

139 views

Here is the simplest C++ program that will print the string, Hello 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; }
Code language: C++ (cpp)

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

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Enable Notifications    OK No thanks