0% found this document useful (0 votes)
5 views

C++ _Hello, World!_ Program

The document provides an introduction to the C++ programming language, specifically focusing on the 'Hello, World!' program, which is a basic example used to demonstrate the syntax of C++. It explains the components of the program, including comments, the main function, and the use of the iostream library for output. Additionally, it emphasizes the importance of including necessary headers and the structure of a valid C++ program.

Uploaded by

Jorge
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

C++ _Hello, World!_ Program

The document provides an introduction to the C++ programming language, specifically focusing on the 'Hello, World!' program, which is a basic example used to demonstrate the syntax of C++. It explains the components of the program, including comments, the main function, and the use of the iostream library for output. Additionally, it emphasizes the importance of including necessary headers and the structure of a valid C++ program.

Uploaded by

Jorge
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Thank you for printing our content at www.domain-name.com.

Please check back soon for new


contents.

66% Learn to code solving problems with our hands-on (https://programiz.pro/learn/master-


off C++ course! Try Programiz PRO today. cpp)

Search PRO
Programiz (https://programiz.pro/learn/master-cpp)
tutorials & examples
(/)
www.domain-name.com

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 often 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
(/cpp-programming/getting-started#local-machine-
install).
C++ "Hello World!" Program
Thank you for printing our content at www.domain-name.com. Please check back soon for new
contents.

66% Learn to code solving problems with our hands-on (https://programiz.pro/learn/master-


off //Try
Your FirstPRO
C++today.
Program
C++ course! Programiz cpp)

#include <iostream>
Search PRO
Programiz (https://programiz.pro/learn/master-cpp)
tutorials & examples
(/)
int main() {
www.domain-name.com
std::cout << "Hello World!";
return 0;
}

Run Code (/cpp-programming/online-compiler)

Output

Hello World!

Working of C++ "Hello World!"


Program
1. // Your First C++ Program

In C++, any line starting with // is a comment (/cpp-


programming/comments). Comments are intended for
the person reading the code to better 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 (/cpp-
programming/library-function/iostream).
This
Thank you for printing allows
our usat
content towww.domain-name.com.
use cout in our program to print
Please check back soon for new
contents. output on the screen.

66% Learn to code solving problems with our hands-on (https://programiz.pro/learn/master-


off C++ course!For now, justPRO
Try Programiz remember
today. that we need to use
cpp)
#include <iostream> to use cout that allows us to print
Search PRO
Programiz (https://programiz.pro/learn/master-cpp)
tutorials & examples
output
(/) on the screen.
www.domain-name.com
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
Thank you for printing execution
our content atof code begins from thePlease
www.domain-name.com. main()
check back soon for new
contents.
function. This function is mandatory. This is a valid C++
program that does nothing.
66% Learn to code solving problems with our hands-on (https://programiz.pro/learn/master-
off C++ course! Try Programiz PRO today. cpp)

int main() {
Search PRO
Programiz (https://programiz.pro/learn/master-cpp)
tutorials & examples
(/) // Write your code here
} www.domain-name.com

In the next tutorial, we will learn about comments in C++.

Share on:

(https://www.facebook.com/sharer/sharer.php? (https://twitter.com/int
u=https://www.programiz.com/cpp- text=Check%20this%2
programming/examples/print-sentence) programming/example

Did you find this article helpful?


Our
Thank you for printing premium
our content atlearning platform, created
www.domain-name.com. with back soon for new
Please check
contents. over a decade of experience.

66% Learn to code solving problems with our hands-on (https://programiz.pro/learn/master-


off Try
C++ course! Try Programiz
Programiz PROPRO
today. cpp)
(https://programiz.pro/)
Search PRO
Programiz (https://programiz.pro/learn/master-cpp)
tutorials & examples
(/)
www.domain-name.com

Related Examples

C++ Example

Print Number Entered by User

(/cpp-programming/examples/read-print-integer)

C++ Example

Check Leap Year

(/cpp-programming/examples/leap-year)

C++ Example

Check Whether Number is Even or Odd

(/cpp-programming/examples/even-odd)

C++ Example

Display Fibonacci Series

(/cpp-programming/examples/fibonacci-series)
Thank you for printing our content at www.domain-name.com. Please check back soon for new
contents.

66% Learn to code solving problems with our hands-on (https://programiz.pro/learn/master-


off C++ course! Try Programiz PRO today. cpp)

Search PRO
Programiz (https://programiz.pro/learn/master-cpp)
tutorials & examples
(/)
www.domain-name.com

You might also like