Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(15 points) Consider the following skeletal C program: void funl (void) prototyp

ID: 3710370 • Letter: #

Question

(15 points) Consider the following skeletal C program: void funl (void) prototype/ void fun2 (void)prototype/ void fun3 (void) prototype/ void main) int a, b, ci void funl (void) i int ?, ?, d; void fun2 (void) i int c, d, ei void fun3 (void) i int d, e, f; Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during execution of the last function called? Include with each visible variable the name of the function in which it was defined a. main calls funl; fun calls fun2: fun2 calls fun3. b. main calls funl; funl calls fun3 c. main calls fun2; fun2 calls fun3; fun3 calls funl d. main calls fun3; fun3 calls funl e. main calls funl; fun1 calls fun3; fun3 calls fun2 f. main calls fun3: fun3 calls fun2; fun2 calls funl

Explanation / Answer

in dynamic scoping the compiler first searches the current block and then successively all the calling functions.

a. main -> f1 -> f2 -> f3
Below are the variables visible.
Note d(f3) means variable d defined in function f3.

So d(f3), e(f3), f(f3), c(f2), b(f1), a(main) are visible.

b. main -> f1 -> f3
d(f3), e(f3), f(f3), b(f1), c(f1), a(main) are visible.

c. main -> f2 -> f3 -> f1
b(f1), c(f1), d(f1), e(f3), f(f3), a(main) are visible

d. main -> f3 -> f1
b(f1), c(f1), d(f1), e(f3), f(f3), a(main) are visible

e. main -> f1 -> f3 -> f2
c(f2), d(f2), e(f2), f(f3), b(f1), a(main) are visible

f. main -> f3 -> f2 -> f1
b(f1), c(f1), d(f1), e(f2), f(f3), a(main) are visible