User Define Function
|What is User Define Function?|
Function is a group of logically related statements that is used to perform specific
|Advantage and Disadvantages of User Define Function|
(1) In a large
and complex programs certain task need to be performed repeatedly for different
input values. If we define User Define Function for that task then there is no need
to write same block of code again and again. So it will reduce length of the program.
|Parts of User Define Function|
There are three
parts of User Define Function:
As it is compulsory
to declare all the variables in C Program it is also compulsory to declare User
Deifne Function in C program. Declaration of Function is also known as Prototype
ReturnType FunctionName (ArgumentList);
ReturnType indicates type of the value returned by the function.
FunctionName indicates name of the function.
ArgumentList is a collection of DataType Variable pair followed by comma.
int sum(int a,int b);
that are passed as an argument to the function are known as formal parameter or
contains actual logic or code to be executed. Function Definition is a collection
of logically related statements that is used to perform specific task.
ReturnType FunctionName (ArgumentList)
Function Body (Group of Statements)
int sum (int a, int b)
c = a + b;
type of the function is void then there is no need to write return statement.
In order to
perform specific task that is defined inside function definition, the control of
the program need to be transfered from main () function to function definition.
is called, compiler will compare function call with function declration to check:
int sum (int a,int b);// Function Declaration
sum(4,5,6); // Function call
above function call will generate error because number of arguments not match.