C++ Program Structure

program structure of c++
The above diagram shows the basic program structure of C++.

Declaration section includes different library functions and header files. All preprocessor directives are written in this section.

Global declaration includes structure, class, variable. All global variables are declared here.

Main() function is an entry point for all the function. Every C++ program starts with main() function.

Example : /* First C++ Program */

#include <iostream>
using namespace std;
int main()
{
     cout<<"Welcome to TutorialRide";
     return 0;
}


Output:
Welcome to TutorialRide

Following are the steps/ parts of the above C++ program:

/* First C++ Program */ /*...*/ comments are used for the documentation to understand the code to others. These comments are ignored by the compiler.
#include<iostream>It is a preprocessor directive. It contains the contents of iostream header file in the program before compilation. This header file is required for input output statements.
int/voidInteger (int) returns a value. In the above program it returns value 0. Void does not return a value so there is no need to write return keyword.
main()It is an entry point of all the function where program execution begins.
Curly Braces {...}It is used to group all statements together.
std::coutIt is requried when we use #include . Std::cout defines that we are using a name (cout) which belongs to namespace std. Namespace is a new concept introduced by ANSI where C++ standard libraries are defined.

If using namespace std is placed into the program then it does not required to write std:: throughout the code. Namespace std contains all the classes, objects and functions of the standard C++ library.
"Welcome to TutorialRide"The words in inverted commas are called a String. Each letter is called a character and series of characters that is grouped together is called a String.
String always be put between inverted commas.
<<It is the insertion stream operator. This operator sends the content of variables on its right to the object on its left.

In the above program, right operand is the string "Welcome to TutorialRide" and left operand is cout object. So it sends the string to the cout object and then cout object displays the string as a output on the screen.