chapter 5 Flashcards

(42 cards)

1
Q

What is a variable?

A

An abstraction of a memory cell.

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

What are the six attributes of variables?

A
  • Name
  • Aliases
  • Value
  • Type
  • Lifetime
  • Scope
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the primary difference in scope for a local variable declared in a block {} in C++ vs. C#?

A

The identifier used to refer to the variable.

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

What does ‘Address’ refer to in variable attributes?

A

The memory address associated with the variable, which can change during execution.

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

What are ‘Aliases’ in relation to variables?

A

When two variable names refer to the same memory location.

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

What does ‘Value’ represent in variable attributes?

A

The content stored in the memory location(s) the variable is associated with.

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

What is the difference between a Keyword and a Reserved Word?

A

Keyword: Special meaning only in certain contexts. Reserved Word: Cannot be used as a user-defined name in any context (has special meaning everywhere).

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

Define ‘Lifetime’ in the context of variables.

A

The time during which a variable is bound to a specific memory cell.

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

Define Binding.

A

An association between an attribute (like type or value) and an entity (like a variable or function name).

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

What is the difference between a Keyword and a Reserved Word?

A

Keyword: Special meaning only in certain contexts. Reserved Word: Cannot be used as a user-defined name in any context (has special meaning everywhere).

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

Define Alias.

A

When two or more variable names (or references) can be used to access the same memory location.

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

Why are Aliases generally considered bad for readability and reliability?

A

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.

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

Define Binding Time.

A

The time at which a binding takes place.

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

Define ‘Binding’.

A

An association between an attribute and an entity.

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

What is the difference between Static Binding and Dynamic Binding?

A

Static Binding: Occurs before runtime and remains unchanged throughout execution. Dynamic Binding: Occurs during execution or can change during execution.

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

List the different binding times.

A
  • Language Design Time
  • Language Implementation Time
  • Compile Time
  • Load Time
  • Runtime
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the difference between Static Binding and Dynamic Binding?

A

Static Binding occurs before runtime and remains unchanged, while Dynamic Binding occurs during execution.

18
Q

What is a Named Constant?

A

A variable that is bound to a value only once and cannot be changed after initialization.

19
Q

What is Static Type Binding?

A

Binding that happens before runtime, usually at compile time.

20
Q

What is the advantage of Static Type Binding?

21
Q

What is Type Inferencing?

A

Type is determined from the variable’s initial value or usage context.

22
Q

Define Dynamic Type Binding.

A

Binding that happens during runtime, allowing a variable to hold values of different types at different times.

23
Q

What are the disadvantages of Dynamic Type Binding?

A
  • Cost (runtime type checking)
  • Difficult for compiler/interpreter to detect type errors
24
Q

What is Storage Binding?

A

Associating a variable with a memory cell.

25
What are the categories of variables by lifetimes?
* Static Variables * Stack-Dynamic Variables * Explicit Heap-Dynamic Variables * Implicit Heap-Dynamic Variables
26
What is a Named Constant?
A variable that is bound to a value only once and cannot be changed after initialisation.
27
How is the Referencing Environment determined in a language with Static Scope?
Back: Local variables + visible variables in all textually enclosing static scopes.
28
Define Explicit Heap-Dynamic Variables.
The collection of all names that are visible in that statement.
29
Which type of scope is generally considered more reliable and easier to read?
Static Scope.
30
What is the difference between Static Scope and Dynamic Scope? Back: Static Scope: Based on the textual layout of the code (search outwards through enclosing blocks/functions).
Dynamic Scope: Based on the calling sequence of program units at runtime (search backwards through the call stack).
31
Define Scope.
The range of statements over which a variable is visible (can be referenced).
32
What is a disadvantage of Static variables (compared to Stack-Dynamic)?
Lack of flexibility (no recursion support), storage cannot be shared.
33
What is an advantage of Stack-Dynamic variables (compared to Static)?
Allows recursion, conserves storage (memory can be shared).
34
Name and briefly describe the four categories of variables based on their lifetimes.
1. Static: Bound to memory before execution, stays bound throughout. 2. Stack-Dynamic: Storage allocated when declaration is elaborated (e.g., function call), deallocated when scope exited. 3. Explicit Heap-Dynamic: Allocated/deallocated by explicit programmer code (new/delete). 4. Implicit Heap-Dynamic: Allocation/deallocation caused by assignment statements
35
Define Lifetime of a variable.
The time during which a variable is bound to a specific memory cell.
36
What is the distinction between Scope and Lifetime?
Scope is the textual region where a name is visible, while Lifetime is the time a variable is bound to a memory cell.
37
What is a Referencing Environment?
The collection of all names that are visible in a statement.
38
What is Type Inferencing?
The compiler determines a variable's type from its initial value or context, binding it statically. (Differs from dynamic binding because the type is fixed statically).
39
List one advantage and one disadvantage of Dynamic Type Binding
Advantage: Flexibility (a variable can hold different types). Disadvantage: Less reliable (type errors caught only at runtime), Higher cost (runtime type checking).
40
What is Static Type Binding?
The type of a variable is determined before runtime and remains fixed.
41
What is Dynamic Type Binding?
The type of a variable is determined during runtime by assignment, and can change during execution.
42
How does Prolog's scope rule work (Static or Dynamic)?
Static Scope. Visibility is determined by the program text structure.