| Function and Recursion |
| |
| Function Declaration |
| |
| Before defining the function, it is desired to declare the function with its prototype. |
| |
| In function prototype, the return value of function, type, and number of argument are specified. |
| |
| Function declaration is written in following ways: |
| |
| return data_type function_name (data_type argument 1, data_type argument 2 ................data_type argument n) |
| { |
| local variable declaration; |
| executable statement 1; |
| executable statement 2 |
| .................................. |
| ................................ |
| executable statement n; |
| return(expession); |
| } |
| |
| Note: An empty pair of parenthesis must follow the function name if the function definition does not include any arguments. |
| |
| Example: |
| |
| If it returns a float than command is: |
| |
| float f1(float arg 1, int arg 2); |
| |
| if it returns no value or return a character, then replace float by void or char respectively. If no arguments passed into a function than command is: |
| |
| char fun1 ( ); |
| |
| An example program using a small add function: |
| |
 |
| |
| Out put of the program |
| |
 |
| |
| |
| |
| |
| |