Sub Programs Flashcards
2 types of sub programs
Procedures
Functions
Procedures
Set of instructions stored under 1 name
Functions
Set of instructions stored under 1 name
Always return a value
What are procedures and functions used for
To repeat a set of instructions throughout the program
Give program more structure + reliability
What are parameters?
Special variables used to pass values into a sub program
You can specify a name, data type, a default value
What are arguments?
The actual values that the parameters take when the sub program is called
What do all variables have?
Scope - tells you which parts of the program the variable can be used in
Local Variables
Only used within the structure that they are declared
Have a local scope
Global Variables
Can be used anytime after they are declared
Have a global scope
Where are local variables declared?
In sub program
Advantages of Local Variables
Do not affect anything outside the sub program
Disadvantages of Global Variables
Hard to keep track of its value in large programs