C Functions

Introduction
A function is a self contained program structure within the main program designed to perform a specific task and return a value. Functions have the following; heading, declarations, statements.

Functions help modularize a program and must be declared before use. Declaration of a function involves; specifying the return (data) type, naming the function and providing (optional) parameters.

Parameters are variables declared within the function header. They allow the exchange of values to take place (parameters are optional).

When a function is called, control is transferred from the point of calling to where the function is defined (into the body of the function).

The function call must use actual variables (which must be equal to the number of variables in the function definition header). The variables should also match in terms of datatype and as declared.

Syntax: returntype functionname (optional parameters) {     statements; return value; }

The function is always expected to return a value, however, a function that does not return a value must be declared with the data type "void". This is equivalent to procedures in other programming languages.

Syntax: void functionname ( optional parameters) {   statements: }

recursive functions
==