Functions and recursion
Programming Fundamentals · Engineering
Study notes
Factorial with recursion in C: int fact(int n){ if(n<=1) return 1; return n*fact(n-1); } Trace fact(4): 4*fact(3) -> 4*3*fact(2) -> 4*3*2*fact(1) -> 4*3*2*1 = 24. Each call waits on the stack until the base case returns.