3.1.1.14 Global variables in a programming language. Flashcards
1
Q
Outline the difference between global and local vairables.
A
Local is declared within a function whereas global is declared outside.
Data sharing is not possible with local as the data can only be accessed by only one function. Global variables allow for data sharing as multiple functions can access the same global variable.
Parameters passing is required for local variables to access the value in other functions whereas, with global, variables are visible throughout the program and therefore, this is not necessary.
2
Q
Why is it not a good idea to use global variables?
A
- Global variables can be overwritten which can lead to confusion.