Question: Problem 2 : Scopes and Symbol Tables Consider the following code: int x = 2 ; void ( * func _ ptr ) ( )

Problem 2: Scopes and Symbol Tables
Consider the following code:
int x =2;
void (*func_ptr)();
bool use_alternate = false;
void g(int y){
if (y>0){
int x = y +2;
g(y -1);
} else {
func_ptr();
}
}
void f(){
print(x);
}
void alt(){
if (}x==2)
x =100;
} else {
int x =7;
x +=3;
}
print(x);
}
void h(){
int x =10;
if (use_alternate){
func_ptr = &alt;
} else {
func_ptr = &f;
}
g(3);
}
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 use_alternate = true. What would the output be under both
static scoping and dynamic scoping?
Problem 2 : Scopes and Symbol Tables Consider the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!