Learn how functions work and how the call stack tracks execution
A function is a reusable block of code that performs a specific task. Functions help you organize code, reduce duplication, and make programs easier to understand and maintain.
`returnType functionName(parameterType parameterName) {
// Function body
return value;
}
`When a function is called:
1. **Push**: The function is added to the call stack
2. **Execute**: The function body runs
3. **Return**: The function returns a value
4. **Pop**: The function is removed from the stack
The **call stack** (shown on the right) shows which functions are currently running. When main() calls add(), add() appears on top of the stack. When add() finishes, it's removed.
Functions that don't return a value use the `void` return type. They perform an action but don't send data back.