int myFunc1( int );
int myFunc2( int );
int myFunc1( int n )
{
// Do something
if(somecodition)
return myFunc2( n );
elsereturn n;
}
int myFunc2( int n )
{
// Do something
if(somecodition)
return myFunc1( n );
elsereturn n;
}
int main()
{
int t = myFunc1( 1 );
}
Technicaly in this case you would only need to prototype int myFunc2( int );.
i would only like to add that the function prototype simply tells the compiler on your behalf that" i am going to use this function in my program. You have all the details (given by the prototype) please make the suitable arrangements "
A prototype is the function declaration, so is better saying
"It's for being able to call the functions at all times, even though its not been necessarily implemented yet"
The C++ standard requires that a symbol be defined before it is used. Function names are symbols.
Why is this useful for functions? So that the compiler can make sure you are calling the function with the right number of parameters and the right type of parameters. Anyone who has done K&R C has probably been bitten more than once by the fact that the compiler didn't complain about a call to foo() with 3 actual parameters, but the function really took 4, and then things didn't quite work right when the program ran.
[NB: Now there's more to this than just what I mentioned above. OO and polymorphism, not to mention templates, would be impossible without prototypes/declarations.]