Hello World Program in C++

0 Suresh Chand March 28, 2021

Here, We are printing the Hello World using C++ program using cout function.

Here, We will write a simple program that will display Hello World message. We will discuss each part in detail.

#include <iostream>
using namespace std;

int main(){
    
    // This is the single comment

    /*  This
     *       is
     *         multiple comment
     */

      cout << "Hello World" << endl;
    
    return 0;
}

The output of the above program is:

Hello World

Let’s discuss all the lines of the above program in detail.

1. Comments

Here we can see two types of comments in the above program. Comments are the explanation or description of source code that does not affect your program logic in any way. Comments are neglected by compilers or interpreters.

// This is single line comments

/*
*    This
*        is
*          the multiple line comment.
*/

2. #include <iostream>

This statement tells the compiler to include iostreamfile from the library. This library contains input-output functions such as coutcin, etc.

3. using namespace std

The namespaceis a region that provides scope to an identifier (functions, variables, and name od the types). Here we have used std as namespacethat tells compiler to look into particular region of identifiers. I will not discuss this topic in details here beacause that may confuse you. We will learn this in details in next chapter with examples that helps you to make clear concept on namespace.

4. init main()

This is the mainfunction of our program from where the program start to execute. intmeans the return type of that function which tells the compiler that this function return integer type value.

5. cout << “Hello World” << endl

coutis an object that is presented in iostrem class. The objective of this is to print the statement as a output. This object print inside the value include in double quote (“”) and it also can display variable values. 

endlis an object of iostremclass which is used to print new line character.

6. return 0

This statement return 0 value from main function which state that execution is completed. return 1 state that execution is failed.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Join Our Newsletter Now

Get the latest tutorials, examples and projects updates.

!

Ads

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Disable Ad Block

Want Same System