Flashcards
Global and Local Variables
Cards in this deck (8)
- 1What are the two ways of storing data?Variables and constants
- 2What is a variable?A space for a single piece of data that has been reserved in the memory so that it can be accessed and changed later in the code. Therefore it contains data that is changed many times while the code is running
- 3What is a constant?A space for a single piece of data that has been reserved in the memory so that it can be accessed later in the code BUT IT CANNOT BE CHANGED
- 4What is a local variable?Visible only in a single module where it is created/declared. They are set/declared inside a function or procedure
- 5What is a global variable?Visible throughout the program and may be accessed from more than one part of the program. They are set/ declared outside any functions or procedures.
- 6Why use global variables?- used where a value needs to be accessible from different parts of a program
- irrespective of the place it was accessed the value will always be the same - 7Why do programmers prefer not to use global variables?- creates testing problems/ to test code within a function the coder will have to runt he entire code
- makes it difficult to maintain/ difficult to see where the variables are being updated/ increases chance of error
- increases coupling which joins several parts of the code together, therefore a change in one module could have an impact on another - 8How do we avoid the problems of global variables?- parameter passing/ keeping it as local in the main code and using a copy of the variable as a parameter by value/ only the copy will be changed
- setting rules (where will they be defines, how much should variables conform)
Information
- Description
- A level Computer Science (Unit 2 - Topic 2) Flashcards on Global and Local Variables, created by Ariana Parr on 20/02/2022.
- Created by
- Ariana Parr
- Views
- 0
- Rating