Variables and Subroutines
This section covers local and global variables, as well as subroutines, functions, and procedures in OCR A Level Computer Science.
Global and Local Variables
The document contrasts local and global variables:
Local variables:
- Accessible only within specific program parts
- Can have same identifier in different subroutines
- Memory released after subroutine finishes
Global variables:
- Accessible anywhere in the program
- Preserved in memory until program ends
- Can make debugging more difficult
Definition: A global variable in computer science is accessible anywhere in a program for its entire execution.
Subroutines, Functions, and Procedures
The text defines and explains:
- Subroutines: Named code sections callable by name
- Procedures: Sets of instructions executed when called
- Functions: Like procedures, but return a value
Benefits of subroutines include improved readability, reusability, and easier testing.
Highlight: Understanding the difference between global and local variables is crucial for effective programming in OCR A Level Computer Science.
Parameters and Arguments
The document explains:
- Parameters: Data passed to subroutines
- Arguments: Actual data pieces passed
- Passing by value vs. passing by reference