General Structure of C++ Program

/* General Structure */
Pre-processor Directives
main ( )
{
Variable Declarations;
Executable Statements;
}

ex:
/* A Simple Program to display a Message * /
#include<iostream.h>
void main( )
{
cout<<” This is the first C++ Program”;
}

Comments or Documentation Section

 Comments are the pieces of code that compiler ignores to compile. There are two types of comments in C++.
1. Single line comment: The comments that begin with // are single line comments. The Compiler simply ignores everything following // in the same line.
2. Multiline comment: The multiline comment begin with /* and end with */ . This means everything that falls between /* and */ is consider a comment even though it is spread across many lines.

Pre-processor Directives 

               The linker section begins with a hash (#) symbol. #include……is a preprocessor directive. It is a signal for preprocessor which runs the compiler.  The statement directs the compiler to include the header file from the C++ Standard library.
Example:
# include<iostream.h>
#include<conio.h>
# include<math.h>

Global Declaration

        We can declare variables here and those variables which are declared before the main function or any other function then the life or scope of such variables remain throughout function and can be used by other functions of the program.

main( ) Function
         As the name itself indicates, this is the main function of every C++ program. Execution of a C++ program starts with main ( ). No C++ program is executed without the main () function. The function main () should be written in the lowercase letter and shouldn’t be terminated with a semicolon.

Statements
          These are instructions to the computer to perform some specific operations. These statements can be expressions, input-output functions, conditional statements, looping statements, function call and so on. They also include comments. Every statement end with semicolon “;” except control statements. Semicolon “;” also known as Terminator.

General Structure of C++ Program General Structure of C++ Program Reviewed by Unknown on 04:25 Rating: 5

No comments:

Powered by Blogger.