There are cases when you need to declare the function prototype beforehand, i.e. the compiler needs to know a functions prototype before you are able to use that function.
Consider these functions that do nothing particularly useful:
int foo(int x)
{
if(x < 1) return x;
else return x + bar(x-1);
}
int bar(int x)
{
if(x < 3) return x;
return x * foo(x-1);
}
If you try to compile this, the compiler gets mad at you:
error: 'bar' was not declared in this scope
You need to put the missing prototypes in front of the function using it:
int bar(int);
// as above unchanged
This is the only case where the compiler requires you to put a function prototype before your functions. In all other cases it is perfectly legal to put prototypes anywhere as often as you'd like, so this is also legal:
int foo(int);
int bar(int);
int foo(int);
int bar(int);
Though obviously redundant (please don't do that). Some people consider it good style to put a function prototype of every function within a file at the top of the file, because
- you don't have to care about cases in which the compiler requires you to do it anymore, and some people apparently cannot interpret the error message by the compiler (which I think is very concise), and
- you see on one view what functions are provided by the file and how they are called.
But this is exactly that, a style discussion. I like to keep my code as short as possible, so I would only use the prototypes that are required by the compiler, but that's purely a matter of taste and convention. When in Rome, do as the Romans or something like that.