• Home
  • 1.1 Printing Hello World

1.1 Printing Hello World

View Categories

1.1 Printing Hello World

< 1 min read

Table of Contents

A C++ program begins execution from the main() function. Statements inside this function are executed sequentially until the program terminates or returns from main().

This example demonstrates the basic structure of a C++ program and uses std::cout to display a message on the standard output stream.

Source Code #

#include <iostream>

int main()
{
    std::cout << "Hello, World!\n";

    return 0;
}

Output #

Hello, World!

Explanation #

  • #include <iostream> includes the standard input/output stream library. It provides objects such as std::cout, std::cin, std::cerr, and std::clog.
  • int main() defines the program entry point. Program execution begins from this function.
  • { } defines the body of the main() function. All statements belonging to the function are enclosed within these braces.
  • std::cout is the standard output stream object used to write data to the console.
  • The insertion operator (<<) sends the string "Hello, World!" to the output stream.
  • '\n' inserts a newline character, causing subsequent output to begin on the next line.
  • return 0; ends the main() function and returns the value 0 to the operating system. A return value of 0 conventionally indicates successful program execution.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *