Question: Problem 2 : Scopes and Symbol Tables Consider the following code: int x = 2 ; void ( * func _ ptr ) ( )
Problem : Scopes and Symbol Tables
Consider the following code:
int x ;
void funcptr;
bool usealternate false;
void gint y
if y
int x y ;
gy ;
else
funcptr;
void f
printx;
void alt
if x
x ;
else
int x ;
x ;
printx;
void h
int x ;
if usealternate
funcptr &alt;
else
funcptr &f;
g;
h ;
Draw the symbol tables for all relevant scopes. Include entries for both
variables and function pointers under static scoping.
What is the expected output when the code is executed using static scoping
and dynamic scoping? Trace through the execution of the program and explain how
x is resolved in each function.
Now, suppose usealternate true. What would the output be under both
static scoping and dynamic scoping?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
