C++ Program Structure

C++ Program Structure

Understand C++ Program Parts

First C++ Program that display output “Welcome to first C++ Program!”.  With example below;

1- C++ Program Comment
 Program comments are helpful statements. These comments help anyone for reading the source code. It is simply a line written by the coder or programmer for his own understanding syntax or to make other understand his program syntax code. The compiler does not include this line while compilation. 
For more detail click here.
2- Header #include<iostream>
It defined standard input/output stream Header files contain definitions of Functions and Variables, which is imported or used into any C++ program by using the pre-processor #include statement.
For example, we are using iostream that is one of the most basic C++ libraries! It is used for input and output.
cin and cout is an example of a function for input and output stream. If you run the program without including iostream then the error will be done because compiler asks no cout , cin library founded.
3- main function
int / void is a return value, which will be explained in a while. The main () is the main function where program execution begins. Every C++ program must contain only one main function.
4- {
Start of the function main
5- Print output code
cout is function for display output in C++. A statement must always terminate with a semicolon; 
6- }
End of the main function
Using namespace std
If you have noticed that C++ language, you may have seen cout being used instead of std::cout. Both name the same object: the first one uses its unqualified name (cout), while the second qualifies it directly within the namespace std(as std::cout).
cout is part of the standard library, and all the elements in the standard C++ library are declared within what is called a namespaceUsing namespace std.

The above program is without using namespace std and here an example with using namespace feature.

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.