Discuss the basic structure of ‘C’ program?
https://www.computersprofessor.com/2016/05/discuss-basic-structure-of-c-program.html
A
C program can be viewed as a group of building blocks called functions.
Structure
of C program
|
It gives brief description about the program
to the user.
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.
|
Linkage
section:
The
link section provides instructions to the compiler to link functions from the
system library.
|
Definition
section:
The
definition section defines all symbolic constants, and user defined constants.
|
Global
declaration section:
There
are some variables that are used in more than one function such variables are
called global variables & are declared in the global declaration section i.e.
outside of all the functions.
|
Main
functions:
Every C program must have one main ( )
function section. This section contains 2 parts. Declaration part &
executable part.
The declaration part declares all
the variables used in the executable part.
There is at least one statement in
the executable part.
These 2 parts must appear between
the opening & the closing braces. The program execution begins at the
opening brace & ends at the closing brace.
All statements in the declaration
& executable parts end with a semicolon (;).
Sub
function section:
It 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.
All sections, except the main
function section may be absent when they are not required.
Ex:
// Program for arithmetic operations
#include<
stdio.h>
# efine PI 3.14
Int a = 8, b =5;
area
(int);
void main ( )
{
int
c, d;
c
= a + b;
printf
(“ sum is % d”, c);
d
= a * b;
printf
(“ product is % d”, d);
area (a);
}
area (int x)
{
float y;
y=
PI * x * x;
printf
(“ area is % f “, y);
}
|