Functions Flashcards
Function
Named list of statements invoked by a function call
Function Definition
New function’s name and a block of statements surrounded by braces
Usually appears before main() in the program file
Return
Causes execution to jump back to original calling location
Parameter
Input to function that can influence behavior
Cannot be a declaration
Argument
Value passed to a parameter
Return Statement
For function to return a value
Only one item can be returned
Multiple return statements can exist in a function
Void Return Type
Function does not return any value
Hierarchical Function Calls
aka Nested Function Calls
Functions included in a function call
Reasons for functions
- Improve program readability
- Modular program development
- Avoid writing redundant code
Function Stub
Function definitions whose statements haven’t been written yet.
Stack Frame
Each function call creates a new set of local variables.
Return causes local variables to be discarded.
Pass By Value
Assigning a normal parameter does not update argument’s variable
Pass By Reference
Updates the argument variable
Append “&” to a parameter’s data type
Local Variable
Variable whose scope is limited to the function it was declared in.
Global Variable
Variable whose scope is the from declaration to the file’s end and reaches into functions.
Use in functions should be limited.