Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C++ “Hello World” Program

C++ “Hello World” Program

This is a simple “Hello, World!” C++ program to display “Hello World” text on the computer screen or display device.

Typically, the best way to learn programming is by writing code. The first program beginners write is “Hello, World!” which is often used to illustrate the syntax of a programming language. You can take a look at the list of Hello World Programs in 300 Programming Languages to see how “Hello, World!” looks like in different programming languages.

Let’s take a look at how “Hello World” program looks in C++.

Example 1: C++ Hello World Program

Output of C++ Program

The first line of this program is a comment which is indicated by double forward slashes i.e. //

Then lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor in C++.

Every C++ program run from the main() function regardless of where the function is actually located within the code.

The cout  is the standard output stream which prints the “Hello, World!” text on the computer screen.

The Phoenix Project
Transform your IT and business with The Phoenix Project – the gripping story that redefines how we think about DevOps and innovation!
View on Amazon

Finally, the return 0;  is the exit status of the program which causes the C++ program to terminate.

Example 2: C++ Hello World Program

Output of C++ Program

About The Author

M. Saqib

Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.