0% found this document useful (0 votes)
17 views1 page

C++ Hello World Program Explained

The document provides an introduction to a basic C++ program that outputs 'Hello, World!' and explains its components, including comments, preprocessor directives, and the main function. It emphasizes the use of std::cout for printing output and the necessity of including iostream. The tutorial is part of a broader learning platform offering various programming courses and tutorials.

Uploaded by

Pavan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

C++ Hello World Program Explained

The document provides an introduction to a basic C++ program that outputs 'Hello, World!' and explains its components, including comments, preprocessor directives, and the main function. It emphasizes the use of std::cout for printing output and the necessity of including iostream. The tutorial is part of a broader learning platform offering various programming courses and tutorials.

Uploaded by

Pavan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Certification courses in Python, Java, SQL, HTML,

CSS, JavaScript and DSA. Try Programiz PRO!

Search... Programiz PRO

Learn more

C++ "Hello,
World!" Program
A "Hello, World!" is a simple program
that outputs Hello, World! on the
screen. Since it's a very simple program,
it's o!en used to introduce a new
programming language to a newbie.

Let's see how C++ "Hello, World!"


program works.

If you haven't already set up the


environment to run C++ on your
computer, visit Install C++ on Your
Computer.

C++ "Hello World!"


Program

// Your First C++ Program

#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
}

Run Code

Output

Hello World!

Working of C++ "Hello


World!" Program
1. // Your First C++ Program

In C++, any line starting with // is a


comment. Comments are intended
for the person reading the code to
be#er understand the functionality
of the program. It is completely
ignored by the C++ compiler.

2. #include <iostream>

The #include is a preprocessor


directive used to include files in our
program. The above code is
including the contents of the
iostream file.

This allows us to use cout in our


program to print output on the
screen.

For now, just remember that we need


to use #include <iostream> to use
cout that allows us to print output
on the screen.

3. int main() {...}

A valid C++ program must have the


main() function. The curly braces
indicate the start and the end of the
function.

The execution of code beings from


this function.

4. std::cout << "Hello World!";

std::cout prints the content inside


the quotation marks. It must be
followed by << followed by the
format string. In our example,
"Hello World!" is the format string.

Note: ; is used to indicate the end


of a statement.

5. return 0;

The return 0; statement is the "Exit


status" of the program. In simple
terms, the program ends with this
statement.

Things to take away


We use std:cout in order to print
output on the screen.

We must include iostream if we want


to use std::cout .

The execution of code begins from


the main() function. This function is
mandatory. This is a valid C++
program that does nothing.

int main() {
// Write your code here
}

In the next tutorial, we will learn about


comments in C++.

Share on:

Did you find this article helpful?

Our premium learning platform,


created with over a decade of
experience.

Try Programiz PRO

Related Examples

C++ Example

Print Number Entered by User

C++ Example

Check Leap Year

C++ Example

Display Fibonacci Series

C++ Example

Check Whether Number is Even or Odd

Free Tutorials Paid Courses

Python 3 Tutorials Master Python

SQL Tutorials Learn SQL

R Tutorials Learn HTML FREE

HTML Tutorials Master JavaScript

CSS Tutorials Master C

JavaScript Tutorials Master C++

TypeScript Tutorials Master Java

Java Tutorials Master DSA with Python

C Tutorials

C++ Tutorials

DSA Tutorials

C# Tutorials

Golang Tutorials

Kotlin Tutorials

Swi! Tutorials

Rust Tutorials

Ruby Tutorials

Online Compilers Mobile Apps

Python Compiler Learn Python App

R Compiler Learn C App

SQL Editor Learn Java App

HTML/CSS Editor Learn C++ App

JavaScript Editor

TypeScript Editor

Java Compiler

C Compiler

C++ Compiler

C# Compiler

Go Compiler

PHP Compiler

Swi! Compiler

Rust Compiler

Ruby Compiler

Company

About

Contact

Blog

Youtube

Careers

Advertising

Privacy Policy

Terms & Conditions

© Parewa Labs Pvt. Ltd. All rights reserved.

You might also like