Recursion vs multiple functions
Just a quick question on recursion. Does it make a difference in terms of speed/resourses/memory/whatever if one uses recursion instead of multiple functions if they both do the same thing? Like for example in this example:
Code:
// if one assumes x is 2
int recursiveFunc(int x)
{
if (x==0)
return 0;
else
return recursiveFunc(x-1);
}
versus
Code:
// if one assumes x is 2
int func1()
{
return func2();
}
int func2()
{
return func3();
}
int func3()
{
return 0;
}
I agree that this is a stupid useless example, but it was the first thing that came to mind :D
Both examples do the same thing, but aside from readability and the fact that the recursive one works for more values of x, is one of these faster/better than the other? I'm just not sure if the computer treats recursion as just another function call or if something different is done. Hope this makes sense... :eek: :)