Structure of C++ Programme

Default Image

C++ programme basically consist on three parts:

  • Preprocessor directives
  • Main function
  • C++ statements

Preprocessor directives


Directive means order. Instructions that
are given to the compiler of C++ before starting the actual compilation
of actual process called preprocessor directives. They are not part of
C++ instructions and doesn’t end with semicolon. At the time of
compilation special instructions are added into the main programme from
directives. Syntax start from number sign (#) and ends with >.
Commonly used preprocessor directives are include and define.


Include directive


Include directive used to add header
files in programme. Header files add special data in the programme.
Sample syntax of include directive is as:


#include


Header files have data about pre-defined
data about different functions that we commonly use in our programme.
Such as information about to get data in programme we use cin or show result on screen use built-in function named cout. These functions data is stored in a header file called iostream.h. We will write it as shown below:


#include


C++ is a case sensitive language. It means that capital and small alphabets have different meanings in programme.


Define directive


Define directive is used in programme to create a constant. This type of constant called macro, sample to write a define directive is as:


#define constant-name value-of-constant


Include directive is used when a user
wants to use some specific value or function in programme, for this
purpose programmer define that constant’s value. So, when ever that
constant name used in programme the value remains same. An example of define directive is written below that help us to understand its working:


#include


#define city Lahore


void main () {


cout << “My city is: ” << city;


}


Output of the programme will be shown as:


My city is: Lahore


Now in this programme whenever the word of “city” will be used it always meant Lahore.


Main function


Main function shows the beginning of c++
programme. Without main function your programme is unable to perform any
type of functionality. When a programme written in c++ start execution,
control directly goes to main function and starts the execution of
statements. Sample syntax of main function is as follow:


void main(void)


{


body of main function


}


C++ statements


Computer language statement is basic unit
of computer programming. Basically, it is an instruction that given to
computer to perform any task. C++ statements are written under main
function between curly brackets. The statements that we write under main
function or any user defined function is know as body of function.
Every statement terminated with the help of semicolon (;). If we didn’t
end a statement with semicolon compiler will shows an error message of
statement missing;.

Read Count: 3 times

Comments

No comments yet.

Leave a Comment