Programmer's Wiki

Hello, world[]

Here is the "Hello, World!" program in C++:


#include <iostream>

int main()
  std::cout << "Hello, World!" << std::endl;

  return 0;


The first line in this program is a preprocessor directive, for inserting the iostream header. This header contains the necessary declarations and definitions for some basic input/output functionality.

The third line (int main()) starts the definition of a function called main. This function is called by the runtime library at program startup. The program will be terminated when we return from main. The int preceding the functions name indicates that main will return a value of type int.

In the fifth line, we use the cout object to write "Hello, World!" followed by line feed to the standard output stdout.

The return statement on the seventh line makes the main function return 0. The value returned from main is normally used as the exit value of the program, and a 0 normally means that there were no errors.