Lecture 5 Flashcards
What is the scope of a variable?
The scope of a variable is the range of statements in which the variable is visible.
When is a variable visible in a statement?
A variable is visible if it can be referenced in that statement.
What are the types of variables based on scope?
Local and non-local variables.
What is static scoping?
A method of linking names to non-local variables so that the variable’s scope can be determined before the program runs.
Which languages support nested static scopes?
Ada
JavaScript
Common LISP
Scheme
Fortran 2003+
F
Python.
Which languages do not support nested static scopes?
C-based languages.
How is a reference to a variable found in a static-scoped language?
The search starts in the subprogram where the variable is referenced. If not found, it continues in the subprogram’s static parent.
Can hidden variables be accessed in some languages?
Yes, for example, in Ada.
What is a hidden variable in static scope?
A variable in an outer scope that is hidden by another variable with the same name in an inner scope.
How are variables typically defined in blocks?
As static dynamic variables.
What are blocks in programming?
Sections of code with their own local variables whose scope is minimized.
Which languages do not allow block scope inside functions?
Java and C#
Where must data declarations appear in C89?
At the beginning of the function, except in nested blocks.
Which languages allow variable declarations anywhere in the function?
C99, C++, Java, JavaScript, C#.
What is a global variable?
A variable defined outside all functions, potentially visible to all functions in the program.