Function Calling Seminar
Function Calling Seminar
Introduction
Function calling is a fundamental concept in programming where one function invokes
another to perform a specific task. In compiler design, function calls are managed using a
stack to track execution flow, parameters, and return values.
1. Caller Function:
- Saves the return address (location to resume execution after the call).
2. Callee Function:
#include <stdio.h>
// Function call
int result = factorial(num);
return 0;
}
- `factorial(5) = 5 * factorial(4)`
- `factorial(4) = 4 * factorial(3)`
- `factorial(3) = 3 * factorial(2)`
- `factorial(2) = 2 * factorial(1)`
- `factorial(1) = 1 * factorial(0)`
|-----------------------|
| factorial(5) |
| factorial(4) |
| factorial(3) |
| factorial(2) |
| factorial(1) |
| factorial(0) (Base) |
Program Output
When executed, the program produces the following output:
Factorial of 5 is 120
Key Takeaways
- Function calls help in modular and reusable code.
- Each recursive call creates a new stack frame until the base case is reached.
- Function calling plays a crucial role in compiler design for managing execution flow.