Home » Structure of ‘C++’ Program

Structure of ‘C++’ Program

C++ is a procedural language with the object oriented extensions. Every C++ program consists of one or more functions and any function can call any function, even a function can call itself i.e. recursion.

In C++, statements are of three main types:

  1. Declaration statements: The statements that declare variables and functions.
  2. Definition statements: The statements that define the instances of variables and functions.
  3. Procedural statements: The statements that include assignments, expressions or control statements.

The structure of C++ program are as shown below:

Comments Section: This section is helpful to understand that what’s going on means that shows the program name or other important things. It have no effect on the executable program because C++ compiler ignores them.
In C++, we can defines comments in two ways:-

  1. /* ———— */, used for commenting a block of code .
  2. //———— . used for single line comment.

Preprocessor Directives: A preprocessor is a program that processes a source file before the main compilation takes place. It is automatically invoked when we compile the program. C++ handles preprocessor directives whose names begins with a sign #. In C++, we use #include<iostream.h> preprocessor directive.
This directive tells the compiler to add the contents of the iostream.h file into source file. The #include directive tells the compiler to include a given source code file in your program. The iostream.h file describes classes, functions and global values for input and output console. The iostream.h file uses the cin and cout for input and output.

External/Global Variable Declaration: The external variable are those variable that are declare here and defined outside the main() function. The global variables that can be used anywhere in the program are declared in global declaration section. This section also declares the user defined functions.

class Definition and Declaration: A class is an organization of data and functions which operate on them. Data types are called data members and the functions are called member functions. The combination of data members and member functions constitute a data object or simply an object.

A class definition is followed by a semicolon(;) as:

class classname
{
// data members
// member functions
};

void main() function: Every C++ program has a main() function. The main() function provides the entry and exit points to the program. The program starts executing with the first statement in main() function and terminates with the last statement in main() function.

The first line of the main() function is called the function heading and the portion enclosed in the braces ( { and } ) is called the function body.

 

 


Leave a comment

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