In previous examples, we’ve had to write our functions above the place where they are called. However, many developers like to place main as their first function they see, so it’s easier to find. Or they may not know the order that the function will be called.
C and C++ allow you to define a function prototype. In that it declares a function without implementing it. This is done at the top of a file, so it can be ready to be used when it is called.
The main difference in the prototype and the function is that there is no body in the prototype. It must be implemented later on however.
// function prototypes
int add(int x, int y);
int add(int x, int y, int z);
double add(double x, double y);
int main()
{
// the function body
}
// the functions will be defined/implemented below this line
This lets us know what all the functions will look like, and how to call them from one easy to find spot. This can make our code easier to read when we have a large number of files to work with.
When we create our own libraries of files to import, this will be an important step, as it will be our prototypes we import.
Function Prototypes was originally found on Access 2 Learn