Wednesday, May 13, 2009

Basic structure of C programs

.....Documentation Section
.....
.....Link Section
.....
.....Definition Section
.....
.....Global declaration Section
.....
.....main() function section
.....{
..........Declaration Section
.....
..........Executable Section
.....}
.....Sub-program Section
.....function1
.....{
..........Statements
.....}
.....function2
.....{
..........Statements
.....}
.....function3
.....{
..........Statements
.....}

The documentation section consists of a set of comment lines giving the name of the program, the author and other details such as a short description of the purpose of the program.

The link section provides instructions to the compiler to link functions from the system library.

The definition section defines all the symbolic constants. The variables can be declared inside the main function or before the main function.

Declaring the variables before the main function makes the variables accessible to all the functions in a C language program, such variables are called Global Variables.

Declaring the variables within main function makes the usage of the variables confined to the main function only and it is not accessible outside the main function.

Every C program must have one main function. Enclosed in the main function is the declaration and executable parts.

In the declaration part we have all the variables.

There is atleast one statement in the executable part.

The two parts must appear between the opening and closing braces

The sub-program section contains all the user-defined functions that are called in the main function.

User-defined functions are generally placed immediately after the main function although they may appear in any order.

No comments:

Post a Comment