Hello World Program in C++

Hello, World program in C++ | it is a simple program written in C++ programming language, which displays the line “Hello, world!” to the output screen or console window. Generally, it is used to introduce the beginners as their first program in C++.

Mainly “Hello, Wolrd!” program is written by the beginners to know the basic things that are required in most C++ programs. It is also used to test that software to develop/compile/run the C++ program is installed or configured properly or not.

Now, let us write the Hello, World! Program in C++,

#include<iostream>
using namespace std;
int main()
{
  cout << "Hello, World! ";
  return 0;
}

Output:-

Hello, World!

The Hello World program can be also written as,

#include<iostream>
int main()
{
  std :: cout << "Hello, World!";
  return 0;
}

Output:-

Hello, World!

Explanation of Program

#include <iostream>

This line includes the iostream header file. The #include directive tells the compiler to include a file. iostream is a standard C++ input/output library file.using namespace std;

This line tells the compiler that we are "using" the "namespace" "std" in our file. We use the namespace std to make it easier to reference operations included in that namespace.

If we hadn’t used the namespace, we had written std::cout instead of cout. This tells the compiler that every cout is actually std::cout.

A semi-colon ; is used to end a statement. Semi-colon character at the end of the statement is used to indicate that the statement is ending there.int main() {}

This line declares a function main which returns integer data. Every C++ program must have a main function. The execution of every C++ program starts from the main function. The code inside {} is called the body of the main function, the opening braces ‘{‘ indicates the opening of the main function and the closing braces ‘}’ indicates the end of the main function.

cout << "Hello World!";

This line tells the compiler to display the message Hello World!return 0;

This is the return statement used to return a value from a function and indicates the finishing of a function.

Hello World Program without using Semicolon

#include<iostream>
int main()
{
  if(std :: cout << "Hello, World!") {}
  return 0;
}

Output:-

Hello, World!

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *