Functions
Reasons for Using Function
- saves repetition of common routines
- modularizes the program, making it easier to use:
- allows recursive processes
Function Definition ANSI
return-type function-name(argument definitions)
{
local variable definitions
statements
}
Function Declaration ANSI (Prototype)
return-type function-name(argument declarations);
Function Definition K&R
return-type function-name()
argument definitions
{
local variable definitions
statements
}
Function Declaration K&R (Prototype)
return-type function-name();
calling functions
- A function is an expression of the return type.
- The argument list is a comman separated list of argument expressions.
- Each argument expression is evaluated, copied (pass by value) and then converted to its corresponding argument type when calling the function.