Unit 2 - C ++ Program Characteristics

Posted on Friday, May 7, 2010 by B[H] | 0 comments
Labels:

Let us examine the program in detail. C++ program is made of a few components. They are:

1-Comments

Comments are used to insert remarks into the source code help to explain about what the program does. In C++, comments can be place anywhere in the programs. It can be used to include the details of the project and the programmer who wrote or modified the code.
There are two types of comment used. They are:

a. Multi-line Comment

This type of comment is begins with a /* (slash followed by an asterisk) symbol and ended with a */ (asterisk followed by an slash) symbol.

This type of comment is good to be used when comments written are longer than 1 line.

Example:
/* This is a program that computes the sum of two integer
numbers */



b. Single line Comment

This type of comment is used with the // (double slash) symbol and it stops at the end of that particular line.
This type of comment can be used when the remark is only 1 line in length.

Example:

// This is a preprocessor



2- Header Files

Header files contain information that is required to run a program. It is a pre written and tested function that comes together with the compiler and is available for the use of the programmers. The format or structure for using the header file is by using the #include directive. The second line in our program 2.1 #include is called an include preprocessor directive. As the file is placed before program the program proper , it is called a header file (with the file extension .h)

Example :
Photobucket



3-Functions

A function is a block of statements that is part of a large programme.

a. Function main( )

A C++ program must have at least the function main( ). Every C++ function, including main( ), must have a body enclosed in braces { }.

b. Function block { }

The function body, also called block can be of any size. The function always ends with the return command.

{ - begin block

} - end block


Example:

main ( )
{

}

No comments:

Post a Comment