Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

C++ Program Structure

Table of Contents

C++ Program Structure

Understand C++ Program Parts

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

//C++ Program First Program structure comment 
#include <iostream> 
int main()  
std::cout << "Welcome to c++ Program !"; 
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.
//C++ Program First Program structure comment 
#include <iostream> 
using namespace std;
int main()  
cout << "Welcome to first c++ Program !"; 

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

Fazal Rehman Shamil Click Here to Know More
Instructor, Researcher, Blogger, SEO Expert, Poet and Publisher of International Journal Of Software, Technology & Science ISSN : 2616 - 5325
Dear Professors and Resarchers!You are welome to Cite these tutorials in your research or slides etc. Please don't forget to mention the reference of website. Copy Paste of text is strcitly forbidden. Images can be reuse because images are protected with watermark.

7 Replies to “C++ Program Structure”

  1. The structure gave me the idea, how the programs are written in c++. The true meaning of the header file, I understood after reading the article that using namespace “std” as a standard library saves us from the misery of writing std:: each time we need to give or take output or input respectively.

  2. In this tutorial, we learn about the basic program. #includeiostream is header file, it is for both input or output, using namespace std mean all the elements in the standard c++ library are declared within what is called namespace, int main is the main function. { is the start of function print output. } is the end of the function.

  3. In this tutorial, I learned about program structure that how the program is written in C++. Firstly we use header file, then using namespace std:, the main function and then print out code, write a statement in int function then at the end we return the value.

  4. This is a c++ structure program. Here I experienced two knowledgeable programs. The first one is that how can we display output without using the namespace. And the other program is that can we displaying output with the use of namespace.
    Thank you, sir!

  5. Sir in these tutorial you tells us about the basics of the programming how we start the program…What is the function of the pragrams…

  6. thanks, sir. Structure of the C++ program is how we write a program in C++. We use header file(#include, and use user namespace which identifies the name, we use main function(int main () ) and write statement int the function and at the end, we return the value.

  7. In this tutorial, I learned about program structure that how the program is written in the given example. First program comment is used (useful for a programmer)then we write header file or preprocessor (#iclude, using namespace std;) and then the main function and then print output code and at the end (cout)that is declared in (using namespace std;)and the program ends.

Leave a Reply

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