Introduction
In this post, I am going to explain a simple c++ program which is displaying the simple message. This is just the introduction. So, let’s begin.
Printing a Simple Message
//Simple C++ Program
#include <iostream>
using namespace std;
int main()
{
cout<<"Welcome to C++ Programming"<<endl;
return 0;
}
In the above program, we are just going to display a simple message i.e. Welcome to C++ Programming.
Detailed Explanation
Now, I am going to explain each and every line of this program.
//Simple C++ Program
This is the comment section. This part will be ignored by the compiler. Why? Because we have used // i.e. single line comment. Whatever we will write after this //, compiler will ignore that part.
There are two types of comments in c++. First is single line comment and other is multi-line comment. We have used single line comment in this program. /*……..*/ is multiline comment. When we want to ignore more than one line, we can use this type of comment.
#include <iostream>
This is preprocessor directive that we will use in our c++ program every time. In c programming we use #include<stdio.h> which is standard input output header file. Here, we will use #include<iostream> which is nothing but input output stream. Whatever we read or write, we will use this header file.
using namespace std;
Every identifier that we are going to use has a scope. For this, we can use this statement. The std is the namespace where c++ standard libraries are defined.
int main()
This is the main function. The compiler will start executing the c++ program from this line. This main function will contain a number of statement written inside the { and }. We can call it the main function body.
cout<<“Welcome to C++ Programming”<<endl;
Just like printf function in the c programming, cout is also used to display the output on the console. Whatever is written in the double quotation, same will be displayed on the console.
The endl terminates the line. After this endl, control will transfer to the next line.
return 0;
We have written int before the main() function. That means main function will return an integer value. There is no error so we will return 0 here.