Skip to main content

Hello World Program in C++

Programming Languages

 Welcome to coding world

Hello World Program in C++ 

 by https://houseofinformation31.blogspot.com/


In this guide we will write and understand the first program in C++ programming. We are writing a simple C++ program that prints “Hello World!” message. Let’s see the program first and then we will discuss each and every part of it in detail.

 Hello World Program in C++ 

/*

* Multiple line

* comment

*/

#include<iostream>

 

//Single line comment

using namespace std;

 

//This is where the execution of program begins

int main()

{

   // displays Hello World! on screen

   cout<<"Hello World!";

 

   return 0;

}

Output:

 

Hello World!

 

Let’s discuss each and every part of the above program.

 

1. Comments – You can see two types of comments in the above program

 

// This is a single line comment

/* This is a multiple line comment

* suitable for long comments

*/

Comments as the names suggests are just a text written by programmer during code development. Comment doesn’t affect your program logic in any way, you can write whatever you want in comments but it should be related to the code and have some meaning so that when someone else look into your code, the person should understand what you did in the code by just reading your comment.

 For example:

/* This function adds two integer numbers

 * and returns the result as an integer value

 */

int sum(int num1, int num2) {

   return num1+num2;

}

Now if someone reads my comment he or she can understand what I did there just by reading my comment. This improves readability of your code and when you are working on a project with your team mates, this becomes essential aspect.

 

2. #include<iostream> – This statements tells the compiler to include iostream file. This file contains pre defined input/output functions that we can use in our program.

 

3. using namespace std; – A namespace is like a region, where we have functions, variables etc and their scope is limited to that particular region. Here std is a namespace name, this tells the compiler to look into that particular region for all the variables, functions, etc. I will not discuss this in detail here as it may confuse you. I have covered this topic in a separate tutorial with examples. Just follow the tutorial in the given sequence and you would be fine.

 

4. int main() – As the name suggests this is the main function of our program and the execution of program begins with this function, the int here is the return type which indicates to the compiler that this function will return a integer value. That is the main reason we have a return 0 statement at the end of main function.

 

5. cout << “Hello World!”;The cout object belongs to the iostream file and the purpose of this object is to display the content between double quotes as it is on the screen. This object can also display the value of variables on screen(don’t worry, we will see that in the coming tutorials).

 

6. return 0; – This statement returns value 0 from the main() function which indicates that the execution of main function is successful. The value 1 represents failed execution.

Popular posts from this blog

Key Ecommerce Leader (KEL) Pakistan Awards Event 2024 | Pakistan KEL Awards Winner Tayyub Hussnain (Norwich Street Wear) | 2024 Alibaba.com Pakistan Key E-commerce Leader Winner

 Key Ecommerce Leader (KEL) Pakistan Awards Event 2024 On August 20, 2024, Alibaba.com organized an exceptional event at the Pearl Continental Hotel in Lahore. Participants gained insights into global business strategies and discovered the vast opportunities available through Alibaba.com. In an exciting development, Alibaba.com announced the launch of Trade Assurance in Pakistan by the end of August 2024, representing a significant advancement for the Pakistani market. Featured speakers included: 🌟 Andrew Zheng - Vice President, Alibaba.com 🌟 Vianne Wang - Head of Global Supply Chain, Alibaba.com 🌟 Winni Chen - Merchant Development Manager The event was a resounding success, enhancing confidence in the future of eCommerce in Pakistan! 💪🎉 During the event, six successful business owners were invited to share their stories and insights. Mr.Tayyub Hussnain stood out with his inspiring success story and impressive leadership skills, captivating the audience and judges alike. Ho...

Pakistan celebrities real ages 2021

  Pakistani Celebrities Ages 2021 A few celebrities hide their age since they have to be shape us get it that they are still energetic. So let’s take a see at the Veritable Age of Pakistani Celebrities and see which celebrity ceaselessly lie around his/her age. 1: Ayeza Khan 15 January 1987 2: Mehwish Hayat 6 January 1988 3: Saba Qamar 5 April 1987 4: Sajal Alay 17 January 1994       5: Sara Khan 14 July 1992 6: Iqra Aziz 24 November 1997     7: Alizeh Shah 9 June 2000 8: Zara Noor Abbas 13 March 1991 9: Saboor Aly 3 March 1995 10: Hina Altaf 2 January 1992 11: Sana Javed   25 March 1993 12: Momal Sheikh   6 April 1986 13: Hiba Bukhari 27 July 1993 14: Hira Mani 27 February 1989 15: Aiman Khan 20 November 1998 16: Minal Khan 20 November 1998 17: Kinza Hashmi 7 March 1997 18: Kubra Khan  16 June 1993 19: Mawra Hoccane 28 September 1992 20: Urwa Hoccane 2 July 1991 21: Ha...

Good Morning Wishes