Hello World Program in C++ with Code Explanation (2024)

By : Barbara Thompson

Updated

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.

You should see a screen something like this

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. To do this select File > New > Source File. The path is shown in the figure below.

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:

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

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

Output

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.

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++.

Summary

  • The “Hello World” program is the first step towards learning any programming language.
  • After installing a C++ compiler and a Text Editor of your choice, you can go ahead and execute your first basic C++ program.
  • The first line is #include . It instructs the compiler to include the standard stream I/O library.
  • : int main(). This is the main function of the program.
  • The operator << writes its second argument onto its first.
  • Return 0; is the last command in the main function which is the return statement.
  • : Cout is a stream that outputs the stream specified.

You Might Like:

  • C++ Polymorphism with Example
  • C++ Operator Overloading with Examples
  • How to Download and Install C++ IDE on Windows
  • C++ Tutorial for Beginners: Learn Programming Basics in 7 Days
  • Difference between Structure and Class in C++
  • C++ Tutorial PDF for Beginners (Download Now)
  • Static Member Function in C++ (Examples)
Hello World Program in C++ with Code Explanation (2024)

References

Top Articles
In rarely seen time situation, LIV pro hit with penalty, is nearly booted
Davis Thompson Wins the John Deere Classic to Earn a Spot in the 2024 Open Championship
Varsity Competition Results 2022
Corgsky Puppies For Sale
Camping World Of New River
Parc Soleil Drowning
How To Pay My Big Lots Credit Card
Justified - Streams, Episodenguide und News zur Serie
Yellow Kitchen Curtains Walmart
Metoprolol  (Kapspargo Sprinkle, Lopressor) | Davis’s Drug Guide
Satucket Lectionary
Irela Torres Only Fans
Rugged Gentleman Barber Shop Martinsburg Wv
New York (NY) Lottery - Winning Numbers & Results
co*cker Spaniel For Sale Craigslist
Fungal Symbiote Terraria
WhirlyBall: next-level bumper cars
Appraisalport Com Dashboard /# Orders
Eaglecraft Minecraft Unblocked
Meineke Pacific Beach
Jeff Danker Net Worth
Restored Republic December 1 2022
Better Health Solutions Bridal Package
Wolf Of Wallstreet 123 Movies
Palm Coast Permits Online
Zuercher Portal Inmates Kershaw County
Cbs Scores Mlb
Are Huntington Home Candles Toxic
Rimworld Prison Break
Krunker.io . Online Games . BrightestGames.com
2010 Ford F-350 Super Duty XLT for sale - Wadena, MN - craigslist
Seller Feedback
Mario Party Superstars Rom
Mike Norvell Height
Cashtapp Atm Near Me
Sam's Club Gas Price Hilliard
Carabao Cup Wiki
Patriot Ledger Obits Today
Everything 2023's 'The Little Mermaid' Changes From the Original Disney Classic
Cpnd Addiction
Sallisaw Bin Store
Vitamin-K-Lebensmittel – diese enthalten am meisten! | eatbetter: gesunde, einfache Rezepte & Tipps für jeden Tag
Epaper Dunya
June 21 2019 Algebra 2 Regents Answers
Joann Stores Near Me
Caldo Tlalpeño de Pollo: Sabor Mexicano - Paulina Cocina
New Application Instructions · Government Portal
Union Corners Obgyn
Conan Exiles Rhino Guide - Conan Fanatics
Signature Learn 365 | airSlate SignNow
How Long Ago Was February 28 2023
Richy Rich Dispensary
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 5938

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.