---
description: In this C++ tutorial, you will learn about a simple C++ Hello World program with a step-by-step explanation of Code.
title: Hello World Program in C++ with Code Explanation
image: https://www.guru99.com/images/cpp-hello-world-program-1.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

The C++ Hello World program is the simplest way to start coding in C++: it prints the text “Hello World” to the screen. Here you will learn to write, compile, and understand your first C++ program line by line.

* 👋 **What it does:** The Hello World program prints the text “Hello World” to the console.
* 📄 **Structure:** It needs an #include header, the main() function, and a cout statement.
* 🖨️ **cout:** std::cout sends text to the screen, and return 0 ends the program.
* ▶️ **Compile & run:** Compile the .cpp file with a C++ compiler, then run the executable.
* 🤖 **AI help:** AI tools like GitHub Copilot write and explain starter C++ code.

[ Read More ](javascript:void%280%29;) 

![C++ Hello World Program](https://www.guru99.com/images/cpp-hello-world-program-1.png)

## Hello World Program in C++

The “Hello World” program is the first but most vital step towards learning any programming language and it is certainly the simplest program you will learn with each programming language. All you need to do is display the message “Hello World” on the output screen.

**Let us now look at C++ Hello World Code:**

**Step 1)** On configuration page. Select create the cache now option.

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF2.png)

You should see a screen something like this

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF3.png)

In some computers and operating systems, it asks whether to include all the libraries. If the option is selected, it will install all the libraries.

**Step 2)** Create a new source file.  
Once the program opens, you need to create a new source file, so you can start writing your first [C++ program](https://www.guru99.com/cpp-tutorial.html). To do this select **File > New > Source File**. The path is shown in the figure below.

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF4.jpg)

This will open an area where you be able to type out your code.

**Step 3)** Now you can write the C++ code. After that you can write the C++ code as shown in the image below:

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF5.png)

C++ Code Example:

#include<iostream>    
using namespace std;    

int main()    
{    
    cout<<"Hello World"<<endl;    
    return 0;    
}    

**Step 4)** Compile your code. In this step, Click on **Execute->compile & run**

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF6.png)

**Step 5)** Save the file. After saving you should see a black screen outputting “Hello World.”

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF7.png)

**Output**

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF8.png)

### RELATED ARTICLES

* [For Loop in C++ with Syntax & Program EXAMPLES ](https://www.guru99.com/cpp-for-loop.html "For Loop in C++ with Syntax & Program EXAMPLES")
* [C++ do…while loop with Examples ](https://www.guru99.com/cpp-do-while-loop.html "C++ do…while loop with Examples")
* [Top 24 C++ Interview Questions and Answers (PDF) ](https://www.guru99.com/cpp-interview-questions.html "Top 24 C++ Interview Questions and Answers (PDF)")
* [How to Download and Install C++ IDE on Windows ](https://www.guru99.com/cpp-ide-download-install.html "How to Download and Install C++ IDE on Windows")

## Your First Program: C++ “Hello World!” Explanation

C++ is a compiled language. The source code is compiled into object files. Object files are then combined by a linker creating an executable program.

A production C++ consists of many source code files (usually called source files).

* Curly braces, {}, express grouping in C++. Here, they indicate the start and end of the function body.
* Every C++ program has exactly one global function named main (). The program starts by executing that function. An int value is returned by main (), which it passes to the system.’ If no value is returned, then the system will receive a value 0 thus indicating successful completion. A nonzero value from the main () function indicates failure.

[](https://www.guru99.com/images/c-sharp-net/052716%5F1044%5FInstallandF9.png)

## Explanation of C++ Hello World Program Code

**Code line 1:** The first line is #include <iostream>. It instructs the compiler to include the standard stream I/O library. Without this header inclusion the expression would not compile.

std::cout << "Hello, World"<<endl

**Code line 4:** int main(). This is the main function of the program. Functions are denoted by the parentheses(). Before the main function is “int”. This means that the main function will return an integer to the function or process that called it.

Don’t worry about this, for the time being, simply note that the program must return an integer before the end. The curly braces, { and }, contain the code within a function. The program terminates, at the end of the main function denoted by }

**Code line 6:** The operator << writes its second argument onto its first. In this case, the string literal “Hello, World!” is written onto the standard output stream std:: cout.

(**Note**: A string literal is a sequence of characters surrounded by double quotes. endl inserts a newline character on the same line)

**Code line 7:** return 0; This is the last command in the main function, the return statement. Its purpose is only to return a value to the function or process that is called the main function. Don’t worry about this other than the fact that it is required by the “int” in front of the main function definition. It should return a zero from the main function meaning the program ran successfully and exited.

cout<<"Hello World"<<endl;

Note: Cout is a stream which outputs to the stream specified. It is by default the standard output stream. Cout is very common in programs as the ultimate motive in every program is to give some output. endl; represents the end of statements in C++. The semicolon in C++ separates different statements and must be put at the end of statements in C++.

## How to Compile and Run a C++ Program

Once you have written the Hello World program, you need to compile it into an executable and then run it. The exact steps depend on your compiler or IDE.

Using the g++ compiler from a terminal, run the two commands below:

g++ hello.cpp -o hello
./hello

The first command compiles `hello.cpp` into an executable named `hello`, and the second command runs it. In an IDE such as Visual Studio or Code::Blocks, you can build and run the program with a single button. When the program runs, it prints Hello World to the console.

## FAQs

👋 What is the Hello World program in C++?

The Hello World program is a simple C++ program that prints the text “Hello World” to the screen. It is the traditional first program used to learn a language’s basic syntax.

📄 What is the basic structure of a C++ program?

A basic C++ program includes a header with #include, a main() function where execution begins, statements inside braces, and a return 0 statement that ends main().

🖨️ What does cout do in C++?

cout is the standard output stream in C++. Used with the insertion operator, it sends text or values to the console, such as cout for printing Hello World.

📚 Why is the iostream header needed in C++?

The iostream header, added with #include, provides the cout and cin streams. Without it, the compiler cannot recognize cout, so the program fails to print output.

▶️ How do you compile and run a C++ program?

Save the code with a .cpp extension, compile it with a compiler such as g++ (g++ hello.cpp -o hello), then run the produced executable from the terminal or IDE.

🤖 How can AI tools like GitHub Copilot help write C++ programs?

AI assistants like GitHub Copilot generate a complete Hello World program from a comment, explain each line, and suggest fixes for syntax errors as you type.

🧠 Can AI explain C++ code to beginners?

Yes. AI-powered tools describe what #include, main(), and cout do in plain language, making a first C++ program easier for beginners to understand.

⚠️ What is a common mistake in a C++ Hello World program?

Common mistakes include forgetting the semicolon after a statement, omitting the iostream header, or misspelling cout. Each causes a compiler error that stops the build.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/cpp-hello-world-program-1.png","url":"https://www.guru99.com/images/cpp-hello-world-program-1.png","width":"700","height":"250","caption":"C++ Hello World Program","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/cpp-hello-world-program.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/cpp","name":"CPP"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/cpp-hello-world-program.html","name":"Hello World Program in C++ with Code Explanation"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/cpp-hello-world-program.html#webpage","url":"https://www.guru99.com/cpp-hello-world-program.html","name":"Hello World Program in C++ with Code Explanation","dateModified":"2026-08-06T13:15:31+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/cpp-hello-world-program-1.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/cpp-hello-world-program.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/benjamin","name":"Benjamin Walker","description":"I'm Benjamin Walker, an expert in C, C++, and C# programming, providing resources to enhance your coding proficiency and project outcomes.","url":"https://www.guru99.com/author/benjamin","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/benjamin-walker-author.png","url":"https://www.guru99.com/images/benjamin-walker-author.png","caption":"Benjamin Walker","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"CPP","headline":"Hello World Program in C++ with Code Explanation","description":"In this C++ tutorial, you will learn about a simple C++ Hello World program with a step-by-step explanation of Code.","keywords":"bigdata, programming, database, server","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/benjamin","name":"Benjamin Walker"},"dateModified":"2026-08-06T13:15:31+05:30","image":{"@id":"https://www.guru99.com/images/cpp-hello-world-program-1.png"},"copyrightYear":"2026","name":"Hello World Program in C++ with Code Explanation","subjectOf":[{"@type":"HowTo","name":"How to write C++ Hello World Code","description":"Here is a step by step processon how to write C++ Hello World Code:","step":[{"@type":"HowToStep","name":"Step 1) On configuration page.","text":"Select create the cache now option.","image":"https://www.guru99.com/images/c-sharp-net/052716_1044_InstallandF2.png","url":"https://www.guru99.com/cpp-hello-world-program.html#step1"},{"@type":"HowToStep","name":"Step 2) Create a new source file.","text":"Once the program opens, you need to create a new source file, so you can start writing your first C++ program. To do this select File &gt; New &gt; Source File. The path is shown in the figure below.","image":"https://www.guru99.com/images/c-sharp-net/052716_1044_InstallandF4.jpg","url":"https://www.guru99.com/cpp-hello-world-program.html#step2"},{"@type":"HowToStep","name":"Step 3) Now you can write the C++ code.","text":"After that you can write the C++ code as shown in the image below","image":"https://www.guru99.com/images/c-sharp-net/052716_1044_InstallandF5.png","url":"https://www.guru99.com/cpp-hello-world-program.html#step3"},{"@type":"HowToStep","name":"Step 4) Compile your code.","text":"In this step, Click on Execute-&gt;compile &amp; run","image":"https://www.guru99.com/images/c-sharp-net/052716_1044_InstallandF6.png","url":"https://www.guru99.com/cpp-hello-world-program.html#step4"},{"@type":"HowToStep","name":"Step 5) Save the file.","text":"After saving you should see a black screen outputting 'Hello World.'","image":"https://www.guru99.com/images/c-sharp-net/052716_1044_InstallandF8.png","url":"https://www.guru99.com/cpp-hello-world-program.html#step5"}]},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the Hello World program in C++?","acceptedAnswer":{"@type":"Answer","text":"The Hello World program is a simple C++ program that prints the text \"Hello World\" to the screen. It is the traditional first program used to learn a language's basic syntax."}},{"@type":"Question","name":"What is the basic structure of a C++ program?","acceptedAnswer":{"@type":"Answer","text":"A basic C++ program includes a header with #include, a main() function where execution begins, statements inside braces, and a return 0 statement that ends main()."}},{"@type":"Question","name":"What does cout do in C++?","acceptedAnswer":{"@type":"Answer","text":"cout is the standard output stream in C++. Used with the insertion operator, it sends text or values to the console, such as cout for printing Hello World."}},{"@type":"Question","name":"Why is the iostream header needed in C++?","acceptedAnswer":{"@type":"Answer","text":"The iostream header, added with #include, provides the cout and cin streams. Without it, the compiler cannot recognize cout, so the program fails to print output."}},{"@type":"Question","name":"How do you compile and run a C++ program?","acceptedAnswer":{"@type":"Answer","text":"Save the code with a .cpp extension, compile it with a compiler such as g++ (g++ hello.cpp -o hello), then run the produced executable from the terminal or IDE."}},{"@type":"Question","name":"How can AI tools like GitHub Copilot help write C++ programs?","acceptedAnswer":{"@type":"Answer","text":"AI assistants like GitHub Copilot generate a complete Hello World program from a comment, explain each line, and suggest fixes for syntax errors as you type."}},{"@type":"Question","name":"Can AI explain C++ code to beginners?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI-powered tools describe what #include, main(), and cout do in plain language, making a first C++ program easier for beginners to understand."}},{"@type":"Question","name":"What is a common mistake in a C++ Hello World program?","acceptedAnswer":{"@type":"Answer","text":"Common mistakes include forgetting the semicolon after a statement, omitting the iostream header, or misspelling cout. Each causes a compiler error that stops the build."}}]}],"@id":"https://www.guru99.com/cpp-hello-world-program.html#schema-94248","isPartOf":{"@id":"https://www.guru99.com/cpp-hello-world-program.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/cpp-hello-world-program.html#webpage"}}]}
```
