Calling a function

A function call may be used to supply a value of its specified type anywhere that such a value is required. The call consists of the identifier for the function, followed by a list of parameters enclosed in parentheses.Each actual parameter given must match that specified in the function declaration and each formal parameter in the declaration must be matched by an actual parameter in the call. Where no parameters are specified in the function declaration, empty parentheses must be typed.

When a function of type void is called it can only be as a statement.

Example

#include <stdio.h>

    void PrintTwo(int Val1, int Val2) {
        /* Print 2 ints on a line */
        printf("%d %d \n",Val1,Val2);
    }
    
    int Larger(int IVal1,int IVal2) {
        /*Return the larger of 2 ints*/
        if (IVal1>IVal2) return IVal1;
        return IVal2;
    }
    
    void main() {
        int X;
        X = -100; 
        PrintTwo(X,Larger(X,200));
    }
Plain text to compile and run.

Exercises on this section.


Next - Function prototypes.

Back to Contents page.