Answer:
In dynamic scoping the current block is searched by the compiler and then all calling functions consecutively e.g. if a function a() calls a separately defined function b() then b() does have access to the local variables of a(). The visible variables with the name of the function in which it was defined are given below.
Step-by-step explanation:
a. main calls fun1; fun1 calls fun2; fun2 calls fun3
Solution:
- Visible Variable: d, e, f Defined in: fun3
- Visible Variable: c Defined in: fun2 ( the variables d and e of fun2 are not visible)
- Visible Variable: b Defined in: fun1 ( c and d of func1 are hidden)
- Visible Variable: a Defined in: main (b,c are hidden)
b. main calls fun1; fun1 calls fun3
Solution:
- Visible Variable: d, e, f Defined in: fun3
- Visible Variable: b, c Defined in: fun1 (d not visible)
- Visible Variable: a Defined in: main ( b and c not visible)
c. main calls fun2; fun2 calls fun3; fun3 calls fun1
Solution:
- Visible Variable: b, c, d Defined in: fun1
- Visible Variable: e, f Defined in: fun3 ( d not visible)
- Visible Variable: a Defined in: main ( b and c not visible)
Here variables c, d and e of fun2 are not visible .
d. main calls fun1; fun1 calls fun3; fun3 calls fun2
Solution:
- Visible Variable: c, d, e Defined in: fun2
- Visible Variable: f Defined in: fun3 ( d and e not visible)
- Visible Variable: b Defined in: fun1 ( c and d not visible)
- Visible Variable: a Defined in: main ( b and c not visible)