3.1.1.14 Global variables in a programming language. Flashcards

You may prefer our related Brainscape-certified 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why is it not a good idea to use global variables?

A
  • Global variables can be overwritten which can lead to confusion.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly