The Section Of The Structure Discussed In Deeply. 

In this post we are discussed about the different section of the C++ structure. The structure of the C++ program give a basic overview for how to write the simple program in C++. Define a structure of C++ that dived the program into different section.

For know about the structure of C++ program with diagram..

If you click on above link in this we are discussed about the structure of C++ with example and also described that which section are required for the write the basic C++ program. Now here we are discussed about in detail of different section of structure of C++ program. It is a common practice to organize a program into three separate file. The class declarations are placed in a header file.  


The above diagram shows the different section and we discussed in detail of all section. So let's start. And below is a simple structure of a C++ program with example.

// This is a simple C++ program. ➡️ // This is comment section and ignored                                                                                by C++ compiler.                                                  

#include<iostream> ➡️  // Header Section
using namespace std; ➡️ // This tells the compiler use this namespace.
int main()  ➡️ // main function.
{
    std::cout<<"Hello World"; ➡️ this is the body of the main function and                                                                        compiler and  execute this parts.
    return 0;                       
}

1.  Comments. (This is a simple C++ program)

The first line contain the comments which is inserted by the programmer. And this line is ignore by the C++ compiler. Put the comments in program is a very good practice. Because after some time we forget that why we use this concept. So put the comments is very important. And in above program the first line gives the intro or say brief information about the program.

2. Header Section  (#include<iostream>)

Lines begin with the "#" sign are directives and it is known as a preprocessor. They are the special preprocessor which is check before the compilation of the C++ program. The header files tells the preprocessor to include the C++ header which are required for this program. The above header of iostream tells to perform the standard Input and Output operation. 

3. main function (Member Function Definition)

The function is a group of a statement. Here the function is a main(). The program is a starting the execution of program. In C does not specify the any return type of the value but in C++ function main return an integer value. Many operating systems test the return value to determine if there is any problem. The normal convention is that an exit value of zero means the program ran successfully, while a nonzero value means there was a problem. The explicit use of return 0 statement will indicate that the program was successfully executed.

4. { and } (Curley braces)

The open  braces ({ ) indicate the starting of the main program. And close brace ( } )
indicate the end the program. Everything between two brace is the function's body which are execute by the C++compiler. And tells what happen in this body. All function use both braces. 

5.  std::cout<<" Hello World"; (In the body)

The above lines produce some effect. This lines specifying it's actual some behavior. The structure of C++ gives a facilities of this type. The above statement dived into three parts, first std:: cout means Standard Character Output device. Second is the insertion operator(<<) which indicates the follow things is inserted. Finally thee third is the sentences with the quotes("Hello World") which is printed by the compiler on output console.  

Notes:
 All statements of the C++ program ends with the semicolon (;)

The most important thing that structure of a C++ is also know the Client-Server model. Because the class definition includes the member function constitutes the server that provides the service to the main program known as the Client. The client uses the server to the public interface of the class. 

Now you can try yourself to write the structure of C++ program and understand the client-server model.



Comments

Popular posts from this blog

Datatypes In C++

call by value, pointer, reference

Operators in C++