chapter 5 Flashcards
(42 cards)
What is a variable?
An abstraction of a memory cell.
What are the six attributes of variables?
- Name
- Aliases
- Value
- Type
- Lifetime
- Scope
What is the primary difference in scope for a local variable declared in a block {} in C++ vs. C#?
The identifier used to refer to the variable.
What does ‘Address’ refer to in variable attributes?
The memory address associated with the variable, which can change during execution.
What are ‘Aliases’ in relation to variables?
When two variable names refer to the same memory location.
What does ‘Value’ represent in variable attributes?
The content stored in the memory location(s) the variable is associated with.
What is the difference between a Keyword and a Reserved Word?
Keyword: Special meaning only in certain contexts. Reserved Word: Cannot be used as a user-defined name in any context (has special meaning everywhere).
Define ‘Lifetime’ in the context of variables.
The time during which a variable is bound to a specific memory cell.
Define Binding.
An association between an attribute (like type or value) and an entity (like a variable or function name).
What is the difference between a Keyword and a Reserved Word?
Keyword: Special meaning only in certain contexts. Reserved Word: Cannot be used as a user-defined name in any context (has special meaning everywhere).
Define Alias.
When two or more variable names (or references) can be used to access the same memory location.
Why are Aliases generally considered bad for readability and reliability?
Readability: Hard to track changes as a value can change through multiple names. Reliability: Changes through one name can have unexpected effects when accessing through another.
Define Binding Time.
The time at which a binding takes place.
Define ‘Binding’.
An association between an attribute and an entity.
What is the difference between Static Binding and Dynamic Binding?
Static Binding: Occurs before runtime and remains unchanged throughout execution. Dynamic Binding: Occurs during execution or can change during execution.
List the different binding times.
- Language Design Time
- Language Implementation Time
- Compile Time
- Load Time
- Runtime
What is the difference between Static Binding and Dynamic Binding?
Static Binding occurs before runtime and remains unchanged, while Dynamic Binding occurs during execution.
What is a Named Constant?
A variable that is bound to a value only once and cannot be changed after initialization.
What is Static Type Binding?
Binding that happens before runtime, usually at compile time.
What is the advantage of Static Type Binding?
Writability.
What is Type Inferencing?
Type is determined from the variable’s initial value or usage context.
Define Dynamic Type Binding.
Binding that happens during runtime, allowing a variable to hold values of different types at different times.
What are the disadvantages of Dynamic Type Binding?
- Cost (runtime type checking)
- Difficult for compiler/interpreter to detect type errors
What is Storage Binding?
Associating a variable with a memory cell.