What are the design issues for names?
The primary design issues are whether names are case sensitive and whether the special words of the language are reserved words or keywords .
What is the potential danger of case-sensitive names?
They hurt readability because similar-looking names (like Rose and rose) mean different things.
In what way are reserved words better than keywords?
Reserved words cannot be redefined, preventing confusion; keywords can be redefined.
What is an alias?
When two or more variable names access the same memory location.
Which category of C++ reference variables is always aliases?
Reference variables and dereferenced pointers that point to the same location are always aliases
What is the l-value?
The address of a variable used on the left side of an assignment.
What is the r-value?
The value of a variable used on the right side of an assignment.
Define binding.
Connecting an attribute to an entity.
Define binding time.
The moment when a binding occurs.
When can bindings take place?
Compile time, link time, load time, run time.
Define static binding and dynamic binding.
Static Binding: Occurs before run time and stays unchanged throughout execution.
Dynamic Binding: Occurs during run time or can change during execution
What are the advantages and disadvantages of implicit declarations?
Advantage: It is a minor convenience for programmers.
Disadvantage: It hurts reliability because the compiler cannot detect typo errors (e.g., misspelling a variable name creates a new variable instead of an error)
What are the advantages and disadvantages of dynamic type binding?
Advantage: Provides great programming flexibility (e.g., writing generic code).
Disadvantages: It makes programs less reliable (error detection is lost) and increases the cost of execution time.
Define Static variables, and their advantages/disadvantages
The variable is bound to storage before execution; efficient but no recursion.
Define Stack-dynamic variables, and their advantages/disadvantages
The variable is bound to storage when their declaration statement is reached; supports recursion with overhead.
Define Explicit heap-dynamic variables, and their advantages/disadvantages
Explicit heap-dynamic variables are nameless (abstract) memory cells that are
allocated and deallocated by explicit run-time instructions; good for dynamic structures.
Define Implicit heap-dynamic variables, and their advantages/disadvantages
The variable is bound to heap storage only when they are assigned a value; flexible but slow and error-prone.
Define lifetime, scope, static scope, and dynamic scope.
Lifetime: How long a variable is bound to memory
Scope: The range of statements where the variable is visible.
Static Scope: Determined by the text layout before running.
Dynamic Scope: Determined by the call chain while running.
How is a reference to a nonlocal variable in a static-scoped program connected to its definition?
The compiler first searches the local declarations. If not found, it searches the “static parent” (the enclosing program unit), then that parent’s parent, and so on, until the definition is found
General problem with static scoping.
It often allows more access to variables than is necessary; structure decays as programs change.
What is the referencing environment?
It is the collection of all variables that are visible in that statement.
What is a static ancestor of a subprogram? What is a dynamic ancestor?
Static Ancestor: The enclosing subprogram
Dynamic Ancestor: The calling function
What is a block?
A code section with its own local scope.
What is the purpose of let constructs.
To bind names to values in a small scope.