Explore

Variable Scope Flashcards
OCR GCSE J277 Computer Science specification
Ready to master these flashcards?
Sign in to study with spaced repetition and track your progress.
Sign In to Track ProgressTerms in this set (10)
Variable scope
The part of a program where a variable can be accessed or modified.
Local variable
A variable that is declared within a subprogram and can only be accessed within that subprogram.
Global variable
A variable that is declared outside of subprograms and can be accessed throughout the entire program.
Advantages of local variables
They help prevent unintended changes to data and make subprograms easier to debug and maintain.
Disadvantages of global variables
They can lead to unintended changes to data and make debugging more difficult.
Use of global variables
Global variables are useful for storing data that needs to be accessed by multiple parts of a program.
Use of local variables
Local variables are useful for temporary data that is only needed within a specific subprogram.
Scope of a local variable
Limited to the subprogram or block of code where it is declared.
Scope of a global variable
Accessible throughout the entire program, including all subprograms.
Best practice for variable scope
Use local variables whenever possible to reduce the risk of errors and improve program maintainability.

Want to Learn More?
Get personalised lessons, quizzes, and instant feedback from your AI tutor.
Start Learning