As a definition, it's simply a way to tell the compiler you have a function with a certain name, accepts certain values, and returns a certain type. This can be most similarly related to a variable declaration. There is no definition, but it "exists".
As code, the following is a function prototype/declaration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
// Function Prototype
int myFunc(int, int, double);
// Alternative (and my preferred way of writing prototypes
// use the variable names
// int myFunc(int a, int b, double c);
int main() {
// Calling my function
myFunc(1, 2, 5.0);
return 0;
}
// Function Definition
int myFunc(int a, int b, double c) {
return ((a + b) / c);
}
Essentially a prototype gives you the ability to move your function definitions to the bottom of your program. In C++, you must declare something before using it, and with a prototype, our function is essentially declared (you get an error if you put your function at the end of your program without a prototype).