Education
- Get link
- X
- Other Apps
Structure of C program
Every
C program consists of one or more modules called functions. One of the
functions must be called main. The program will always begin by
executing the main function. Any other function definitions must be
defined separately, either ahead or after main function.
Each
function must contain :
i.
Heading :
A function heading,
which consists of the function name, followed by an optional list of
arguments, enclosed in parentheses.
ii.
Declarations :
A function declarations,
if arguments are included in the heading.
iii.
Compound statement :
A compound
statement, which comprises the reminder of the function.
The structures of a C language program is
given below :
Document Section
|
|||||
Header Files
|
|||||
Definition sections / Symbolic Constants
|
|||||
Global Declaration section
|
|||||
Main() function section
{
}
|
|||||
Subprogram section
(user-defined functions)
|
1. Document section :
Document section 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.
2. Header :
Header files are used for inclusion of functions from the
C language library.
3. Definition section :
Definition section defines all symbolic constants. Symbolic
constants are used for better understanding of certain names that are not
going to change throughout the program.
4. Global declaration section
:
There are some variables that are used in more than one
functions. Such variables are called global variables and are declared
in global declaration section i.e. outside of all the functions. This
section also declares all the user-defined functions.
5. Declaration part and
Executable part :
Every C language program must have one main() function
section. This sections contains two parts :declaration parts and executable
part. The declaration part declares all the variables used in the
executable part. There should be at least one statement in the executable part.
The two parts must appear between the opening and the closing braces. The
program execution beings at the opening brace and ends at the closing brace.
The closing brace of the main function section is the logical end of the
program. All statements in the declaration and end with a semicolon.
6. Subprogram section :
The subprogram section contains all the
user-defined functions that are called in the main () function. User
defined functions that are called in the functions, although they may appear in
any order.
All sections, expect the main function section may
be absent when they are not required.
Comments
Post a Comment