1.5.4 Function Prototypes

As we mentioned previously, the order of our programs matters in C++. Before we can call a function, we need to declare that function.

Sometimes, this is an issue as functions may call each other and it is not possible to put every function first.

To get around this, we can use Function Prototypes.

Function Prototypes

A Function Prototype is a function header that is placed earlier in the code so that the function definition can be placed later.

Function Prototypes are only function headers and they are often placed at the start of the program. They tell the C++ compiler to expect a function with a given header and allow us to declare a function name before we define it.

Functional prototypes are sometimes required to help with circular references, but they are also used by some programmers so that they can put the body of a function after the main function as a personal choice.

Last updated