➤ Hello World! in C++
➤ Print Number in C++
➤ Add 2 Numbers C++
➤ Arithmetic Operation
➤ Sum Avg of 3 Number
➤ Area Program in C++
➤ Simple Interest in C++
➤ Find ASCII value in C++
➤ Swap 2 Number in C++
Flow Control Programs
➤ Even-Odd in C++
➤ +ve, -ve, 0 in C++
➤ Vowel-Consonant
➤ Greatest of 3 no.
➤ Check Leap Year
➤ Calculator Program
➤ Reverse a Number
➤ Sum of Natural Number
➤ GCD of 2 Number
➤ LCM of 2 Number
➤ Find Power in C++
➤ Fibonacci Series in C++
➤ Palindrome Number
➤ Find Factorial in C++
➤ Factorial Using Recursion
➤ Prime Number in C++
➤ Prime Number b/w 1-N
Array
➤ Linear Search in C++
➤ Binary Search in C++
Others
➤ Introduction to C++
➤ Data Types in C++
➤ Range of Data Types
➤ Void main, main vs int main
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!