Function declarations

A function has the form:
    type    identifier ( arg-list ) compound-statement
The arg-list is a list of arguments which should be matched with values whenever this function is called. Each argument must be specified as a type followed by an identifier.

The identifier specified for each argument can be used as a variable of that type within the body of the function (its compound-statement). It will start life with the value passed when the function is called.

The type defines the type of value that is generated when this function is called. If the null type void is specified, this function does not generate a value, it merely carries out the specified actions.

The compound-statement contains the list of declarations and statements which define the actions associated with a call of this function.

Examples of function declarations

A function returning a value
int sum(int i1, int i2)
{
    return i1 + i2;
}

A function not returning a value
void print_to_line(int i)
{
    printf("%d\n",i);
}

Exercises on this section.


Next - more on arguments to functions.

Back to Contents page.