Function Declaration:


Like variables, all functions in a C program must be declared, before they are invoked. A function declaration (also known as function prototype) consists of four parts.

i.                    Function type (return type).
ii.                  Function name.
iii.                Parameter list.
iv.                Terminating semicolon.


They are coded in the following format:

This is very similar to the function header line expect the terminating semicolon. For example:
                        int mul (int m, int n) ; /* Function prototype */

Function Calls:
A function can be called by simply using the function name followed by a list of actual parameters (or arguments), if any, enclosed in parentheses. Example:
                        main ( )
                        {
                                    int y;
                                    y= mul (10, 5);
                                    printf(“\n Multiplication=%d”,y);
                        }
When a compiler encounters a function call, the control is transferred to the function mul ( ). This function is then executed line by line as described and a value is returned when a return statement is encountered. This value is assigned to y.  

Previous                                                                                    Next


Powered by Blogger.