I was trying to write recursion function,to find factorial of a number.
int factorial(int input,int *answer)
{
if ( input ==0 )
{
return 0;
}
*answer = *answer * input;
factorial(input -1, answer);
}
What will you say about this function? Is it tail recursive?
When doing tail recursive functions (especially tail recursive functions) it is often helpful to have a helper function in addition to another function which has a more friendly interface. The friendly interface function really just sets up the less friendly function’s arguments.
By passing an accumulator value you avoid having to use pointers or do any computations upon returning from called functions, which makes the functions truely tail recursive.