Structure of C programs
A C
program is separated into six main
sections. i.e.
1)
Documentation section
2)
Link section
3)
Definition section
4)
Global Declarations section
5)
Main functions section
6)
Subprograms section
1) Documentation
section:
·
It uses comment lines for detail of
program such as name of program, author and date of program.
·
There are two way to give comments
i.e. single line comment and multi line comments.
·
Single line comment is starts with special
character i.e. // (double slash)
·
multi line comments is starts with
special character i.e. /* ( slash and asterisk) and end with */
(asterisk and slash)
2) Link
section:
·
Link section supplies instructions
to the compiler to link function from the system library.
·
In link section pre-processor directive #include<File
name>
Where, file name is different header
file
Ø #include<stdio.h> (Standard input-output header)
It is used
to perform input and output operations using functions scanf() and
printf().
Ø #include<conio.h> (Console input-output header)
It is used to perform console input
and console output operations like clrscr() to clear the screen and getch() to
get the character from the keyboard.
Ø #include<math.h> (Math header )
It is used to perform mathematical
operations like sqrt() - obtain the square root and pow() - the power of a
number respectively.
3) Definition
section:
·
It is define all symbolic constants
with using pre-processor #define
Ø Example - #define PI
3.14
Ø Symbolic constant are written in capital letter.
4) Global
declaration section:
·
The variable used in more than one
functions that variable is called global variable.
·
These global variable declared outside
of all functions called as global declaration section
5) Main()
Function section:
·
Any C program must have one main() function.
·
main() function start with { i.e. left brace and end with } i.e. right brace.
·
main() function section contain two
parts, i.e. Declaration part and Execution part.
o
Declaration part – declared all
variables used in execution part.
o
Execution part – minimum one
statement written in this section.
·
All statements written in main()
ends with ; (semicolon)
·
The compiler starts execution from
the main() function.
·
The return type of the main()
function can be void also not necessarily int.
6) Subprogram
section:
·
It contains all user define
functions.
·
All user define functions are called
in main() function.
·
Subprogram section place after main
function
0 Comments