There is no recursion in that code: if
fn
was recursive, then it wouldn't work as there is no way to "limit" it from infinite recursion - you really need to parameter to do that, or you app will just blow the top off the stack and crash.
This is recursive:
int factorial(int n)
{
if (n <= 1) return 1;
return n * factorial(n - 1);
}
Because it calls the
factorial
function from within the
factorial
function. Because the parameter value changes each time it gets called, the limiting check of "one or less" prevents infinite recursion, and it finally produces the correct result.
I'd suggest you go back to your course notes for the last lecture, and your homework question and read them again, really carefully!