Introduction
Control Statement
- Program to check leap year
- Program to find factorial of the number
- Program to find reverse of the number
- Program to Check Armstrong Number
- Program to find the sum of Natural Numbers using Recursion
- Calculator Program
- Program to identify day of week
- Program to print Fibonacci series
- Check Whether the Number is Even or Odd in C++
Function
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle
- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
Array
Pointer
OOPS
Hello World Program in C++
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.
Contents
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 cout, cin, 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.