Functions Flashcards
Function
A named block of statements that can be called within a program
Purpose of functions
Enable reuse of code
Allow for code modularity
Help write more complex programs
Parameters
Allow variation in function behaviour
Formal Parameters
List of parameters in its definition
Actual parameters/arguments
Whenever the function is called a value must be provided for each of the formal parameters
Pass-By-Value
Only a copy of the value of a parameter is sent to a function
So if there is an original variable, it cannot be changed by the function changing the parameter
Local variable
New variables can be created and used within functions but they disappear when the function ends
Global variable
Global variables can be accessed but not changed
Use the global statement to allow changes to global variable