Sunday, 20 September 2015

structure of c program with an example

As stated earlier in the features of C language, C is structured programming language. It have basic structure that do not have earlier of the languages that are appear before C. One reason getting the popularity of C is also do to its simple structure. Here is the basic structure of C program with an example.



The Sections contained in the ‘C’ structure are:
i) Documentation section: It consists of a set of comment lines giving the name of the program, the author and other details which the programmer would like to use later.

Ex : /* program to find
1. Area of circle
2. Circumference of circle*/
Any block of comment lives must start with ‘/*’ and must ends with ‘*/’

ii) Link section: The link section provides instructions to the compiler to link functions from the system library (or) the user-defined-library. This is performed by the preprocessor directive ‘include’ as follow.
# include
Ex: # include


iii) Definition section: It defines all the symbolic constants and macros.
Ex: # define PI3.1428
# define SQR (x) (x*x)

iv: Global declaration section : There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global Variable and are declared in the global declaration section that is out side the all the functions.
Ex : int C;
Main ( )
{
-----
-----
}
Fun 1( )
{
-----
-----
}
v)main () function section : Every ‘C’ program must have one main ( ) function section. This sectin contains two parts, declaration part and executable part. The declaration part declares all the variables used in executable part. These two parts must be appear between the opening and closing braces.
The program execution begins at opening brace and ends as the closing brace. The closing brace of the main () function section is the logical end of the program. All statements in the declaration and executable parts end with a semicolon.
Ex : main ( )
{
int a;
a = 1 0;
print (“%d”,a);
}
vi) Sub program section : 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.
Ex: Void print ( );
Main ( )
{
Print ( );
}
Void print ( )
{
Print f (“This is user-defined function”);
}
Note: All sections, except the main ( ) function section may be absent when they are not required.

0 comments:

Post a Comment

Scribe to Youtube Channel

Advertisement

Find Us On Facebook

C Programming

More

C++ Tutorial

More

Java Tutorial

More

software engineering

More

MS Office

More

Database Management

More
Top