Consider the following function prototype:
or
Function prototypes include the function signature, the name of the function, return type and access specifier. In this case the name of the function is "Sum". The function signature defines the number of parameters and their types. The return type is "void". This means that the function is not going to return any value. Note that the parameter names in the first example are optional.
In early versions of C, if a function was not previously declared and its name occurred in an expression followed by a left parenthesis, it was implicitly declared as a function that returns an int and nothing was assumed about its arguments. In this case the compiler would not be able to perform compile-time validity checking of the number and type(s) of arguments. The C99 standard requires the use of prototypes.
The function MyFunction expects to be called with an integer argument. By including the function prototype, you inform the compiler that the function takes one integer argument and you enable the compiler to catch incorrectly specified calls.
By placing function prototypes in a header file, one can specify an interface for a library.
In C++, function prototypes are also used in class definitions.
TylerMSFT (2023-01-25). "Function Prototypes". learn.microsoft.com. Retrieved 2023-08-09. https://learn.microsoft.com/en-us/cpp/c-language/function-prototypes?view=msvc-170 ↩
"Function prototypes". www.ibm.com. 2018-10-25. Retrieved 2023-08-09. https://www.ibm.com/docs/es/rbd/9.1.1.2?topic=functions-function-prototypes ↩