25


Functions

C provides functions which are again similar most languages. One difference is that C regards main() as function. Also unlike some languages C does not have procedures - it uses functions to service both requirements.

Let us remind ourselves of the form of a function:

returntype function_name (parameterdef1, parameterdef2, ...)

Let us look at an example to find the average of two integers:

float findaverage(float a, float b)

We would call this function in the main program as follows:

main()

{

float d=5;, y=15, result;

}

Note: The return statement passes the result back to the main program.



drago@scri.fsu.edu
Jan. 1997