STRUCTURE OF A PROGRAM, C++

Every programming language has a particular structure, like other programming language C++ has their own structure for writing program. Basic structure of C++ programming language as follows.


A simple program for demonstrate the basic structure of C++ programming language. Each code explained briefly. 


//my first program in C++
This is a comment line. The comment are ignored by the compiler. All lines beginning with two slash sign(//) are considered comments. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is. If we want multiple lines in a comment it is enclosed between /* and */.

#include<iostream.h>
This is a header file of C++. Lines beginning with a hash sign (#) are directives for the preprocessor. File iostream.h is a header file needed for input or output requirements of the program. The C++ languages several headers, like,<stdio.h><conio.h>, <iostream.h> etc., which contain information that is either necessary or useful to your program. The header file are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include<iostream.h> tells the preprocessor to include the iostream.h standard header file. this specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.

int main()
This line corresponds to the beginning of the definition of the 'main' function. The main function is the point by whee all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it. The instructions contained within this function's definition will always be the first one to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function. The word main is followed in the code by a pair of parentheses '()'. 

Braces '{ }'
Right after these parentheses we can find the body of the main function enclosed in braces '{}'. What is contained within these braces is what the function does when it is executed.

cout<<"Hello World1!";
This line is a statement to print our message "Hello World!" on the screen. A statement is a simple or compound expression that can actually produce some effect. This is the body of the function, main(). All statement within the body should be indented for legibility, and each statement must be terminated by a semicolon. 

return 0;
This is a new type of function, when a program finished running it send the value zero (0) to the operating system, that means the execution of the program is over. 

0 comentários:

Post a Comment

POPULAR THIS MONTH

Blog Archive

Don't You Think this Awesome Post should be shared ??
| STRUCTURE OF A PROGRAM, C++ |