I know this title is duplicated with Is this tail-recursion?, but this is different and I could not get a clue from the previous question. so I have to ask again.
The code:
int sum_n(int n, int *sum)
{
return n && (*sum += n) && sum_n(n - 1, sum);
}
It is said(foreign language source) that, tail recursion have two features:
- The function is self-called
- Only constant stack space is needed
So are these two features the only key factors for judging tail recursion? And whether the logical operator &&
in return statement affects tail recursion or not?
Most of all, is the above code tail recursion?