Questions: Symbol Tables and Scope Resolution

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A program declares a global variable `count` and then declares a local variable also named `count` inside a function. When the compiler resolves the use of `count` inside the function body, how does it determine which declaration to use?

AIt reports an ambiguity error because two declarations with the same name exist
BIt uses the global `count` because global scope takes precedence over local scope
CIt finds the local `count` first because the function's scope table sits higher on the scope stack and is searched before outer scopes
DIt uses whichever declaration was entered into the symbol table most recently, regardless of scope level
Question 2 Multiple Choice

What happens to the symbol table entries for variables declared inside a function when the compiler finishes processing the function body?

AThey are moved to the global symbol table so other functions can reference them
BThe function's scope table is popped from the stack, making those names inaccessible to the surrounding scope
CThey remain in the table but are marked as 'inactive' for future reference
DThey are archived in a separate table used only for error reporting and debugging
Question 3 True / False

When the compiler encounters a name reference (not a declaration), it searches starting from the current innermost scope and works outward through enclosing scopes until it either finds a matching declaration or exhausts all scopes.

TTrue
FFalse
Question 4 True / False

A new entry is added to the symbol table each time a variable name is *used* in the program source code.

TTrue
FFalse
Question 5 Short Answer

Why is a stack the natural data structure for implementing scope resolution, and what do pushing and popping correspond to in the program's structure?

Think about your answer, then reveal below.