User defined function
The functions which are designed by programmer on the basis of their requirement. main( ) is a
user defined function, and it is the starting point of execution of a program.
Function Declaration (Function Prototype )
Syntax : return-type function_name(type1 var1,type2 var2,…….);
Example: int add(int a, int b); int add(int, int);
Note: Function prototypes enable the compiler to verify that functions are called correctly. The
compiler ignores variable names mentioned in the function prototype.
The function declaration is optional if the function is defined before it is used.
General format of function definition
Implementation of the function or writing the task of the function Type of the value returned to
the calling function
return_type function_name (parameter list) Function Header
Local variable declarations Function Body
Executable statements
return statement
Return type
Implementation of the function or writing the task of the function
Type of the value returned to the calling function
return_type function_name (parameter list)
Local variable declarations
Executable statements
return statement
}
The return data type can be any valid data type in C .
If a function does not return a value, the return-value-type is declared as void.
Default returntype is int.
Functions with no parameters and no return values
In this type, there is no data transfer between the calling function and the called function.
But there is flow of control from the calling function to the called function and back
Functions with no parameters and return value
In this type, there is no data transfer between the calling function and the called function. But
there is data transfer from the called function to the calling function..
Functions with parameters and no return value
In this type, there is data transfer between the calling function and the called function. But there
is no data transfer from the called function to the calling function
Functions with parameters and return values
In this type, there is data transfer between the calling function and the called function. When the
parameter passed, the called function can receive data from calling function. When returns a
value, the calling function can receive from the called function.
Functions with multiple return values
In general, a function can rerun at most one value only. But when we use call by reference, we
can return multiple values(That is, we can modify multiple variables)