Yes, tail call recursion is typically faster in functional programming languages (for instance Scheme) where operations on mutable objects are expensive.
In C++, the quality of implementation (tail-call optimisation) comes into play:
> ... unless the factorial_r() at the tail is not really a function call...
Tail calls can be implemented without adding a new stack frame to the call stack. Most of the frame of the current procedure is not needed any more, and it can be replaced by the frame of the tail call, modified as appropriate (similar to overlay for processes, but for function calls). The program can then jump to the called subroutine. Producing such code instead of a standard call sequence is called tail call elimination. Tail call elimination allows procedure calls in tail position to be implemented as efficiently as goto statements ... https://en.wikipedia.org/wiki/Tail_call
To make factorial_r tail-recursive, the compiler could rewrite it as:
1 2 3 4 5 6 7 8 9
unsignedlonglong factorial_r( unsignedint n )
// { return n<2 ? 1 : n* factorial_r(n-1) ; }
{ return factorial_r_rewritten( n, 1 ) ; }
unsignedlonglong factorial_r_rewritten( unsignedint n, unsignedlonglong result )
{
if( n<2 ) return result ;
return factorial_r_rewritten( n-1, result*n ) ; // optimise: eliminate tail-call
}
> May I ask you in which projects you are involved with your qualifications?
I do not have a salaried job with one organisation; usually each week it is something different.
The majority of the projects deal with large scale software infrastructure. I do a fair amount of architecture, design and code reviews; in practise I spend a lot of tome teaching on the job.