Function Prototype

A function prototype is a function declaration that specifies the data types of its arguments in the parameter list.

The compiler uses the information in a function prototype to ensure that the corresponding function definition and all corresponding function declarations and calls within the scope of the prototype contain the correct number of arguments or parameters, and that each argument or parameter is of the correct data type.

Prototype Syntax

A function prototype has the following syntax:


   declaration-specifiers(opt) declarator;  

The declarator includes a parameter type list, which can consist of a single parameter of type void .

In its simplest form, a function prototype declaration might have the following format:

A simple program with a function prototype

       A simple example of a function prototype allowing the function
       to be used before it is defined.
       #include <stdio.h>
    int sum (int, int);
    main (void)
        int total;
           total = sum (2, 3);
        printf ("Total is %d\n", total);
           return 0;
    sum (int a, int b)
        return a + b;