Functions in ‘C’
Language.
Functions are
self-contained blocks, containing statements, which perform a coherent task of
some kind.
Every ‘C’ program is
a collection of functions.
Functions break large
computing Tasks into smaller ones.
Functions avoid the
need for REDUNDANT PROGRAMMING.
Functions increases
the LOGICAL CLARITY of the program.
Functions
specifically makes the user to build a CUSTOMIZED LIBRARY of
frequently used
routines.
Functions also
promote portability of source code.
Properties:
Every ‘C’ program
consists of one or more functions of which main() is
primary function.
Execution of the
program always begins by carrying the instructions in
main() Function Only.
Remaining functions
are subordinate to main() or may be to one
another.
For a program with
multiple functions, the definitions of the functions
may appear in any
order and can be independent of one another.
A function carries
its intended action whenever it is accessed from
several different places
within a program.
Once the function
completes its intended action, control returns to the
point from where the
function was accessed.
A function processes
information that is passed to it from calling portion
of the program, and
returns a single value.
Information is passed
via arguments and value is returned through
return statement.
User defined
functions:
These functions are
generally designed by the programmers, to
customize their
programming sequence
The user-defined
functions have three properties
1) Prototype or
Signature
2) Calling
3) Definition
Prototype:
The information
revealed by a functions prototype is
1. Function name.
2. Data type of
parameters/arguments.
3. Data type of data
returned.
Calling:
The steps fallowed
through calling are:
1. Control jumps to
the memory where the Functions Definition is
located.
2. Function performs
all the instructions provided in the definition in
a sequential manner.
3. After performing
all the instructions control will move to the
Function from where
it was called.
Definition:
Definition is the set
of instructions that become the responsibility of the
function whenever it
is called.
Syntax:
Let us Understand the
Functional Process Flow.
Function Process I
Program
#include<stdio.h>
void main()
{
basic();
printf(“\nIntroduction
to Functions in ‘C’.”);
}
basic()
{
printf(“\nFunction
Basics.”);
return;
}
Function Process II
Program
#include<stdio.h>
void main()
{
printf("\nMain
Control.");
one();
two();
three();
}
Data Type of Return Value
Function Name
(
DataTypeofParameter) ;
one()
{
printf("\nFunction
Ones Duty.");
}
two()
{
printf("\nSecond
Functions Duty.");
}
three()
{
printf("\nThird
Functions Duty.");
}
Function Process III
Program
#include<stdio.h>
void main()
{
printf("\nMain
Control.");
one();
printf("\nReturn
to Main Module.");
}
one()
{
printf("\nFirst
Functions Duty.");
two();
printf("\nControl
Returns to One.");
}
two()
{
printf("\nSecond
Functions Duty.");
three();
}
three()
{
printf("\nThird
Function Duty.");
}
No comments:
Post a Comment