33
Total Posts
3
Categories
24/7
Updated

C++

Hello World in C++

Published on Dec 19, 2025
#include <iostream.h>
int main() {
    std::cout << "Hello World!";
    return 0;
}

Documentation

  • #include <iostream>: This is a preprocessor directive that includes the iostream (input/output stream) library. This library is necessary to use input and output functionalities, such as printing to the console.
  • int main() { ... }: The main() function is where every C++ program begins execution. The code within the curly braces {} is the body of the function and will be executed when the program runs.

  • std::cout (or simply cout): This is the standard output stream object, used to send text to the console.

  • <<: This is the insertion operator, used with cout to insert data into the output stream.

  • "Hello, World!": The text inside the double quotes is a string literal that will be printed to the screen.

  • std::endl (or endl): This inserts a newline character and flushes the output buffer, ensuring the text is immediately displayed on the console. A simpler alternative is to use the newline escape sequence \n inside the string, e.g., "Hello World!\n".

  • ;: A semicolon ends every C++ statement.

  • return 0;: This statement ends the main function and signals to the operating system that the program ran successfully.