203k views
2 votes
Consider the following skeletal C program which uses dynamic scoping. For the calling sequence: main calls fun1; fun1 calls fun2; fun2 calls fun3, which set of variables and the program unit of their declaration are visible within the function sub3? void fun1(void); /* prototype */ void fun2(void); /* prototype */ void fun3(void); /* prototype */ void main() { int a, b, c; . . . } void fun1(void) { int b, c, d; . . . } void fun2(void) { int c, d, e; . . . } void fun3(void) { int d, e, f; . . . }

User Jetcom
by
3.6k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

In dynamic scoping, scoping is defined as per calling sequence.

1. fun3 is last

f is defined in fun3

e is define in fun3

d is defined in fun3

c is visible from fun2

b is visible from fun1

a is visible form main

2. fun3 is last

f is defined in fun3

e is define in fun3

d is defined in fun3

c and b are visible from fun1

a is visible from main

3. fun1 is last

b is defined in fun1

c is define in fun1

d is defined in fun1

e and f are visible from fun3

a is visible from main

4. fun1 is last

b is defined in fun1

c is define in fun1

d is defined in fun1

e and f are visible from fun3

a is visible from main

5. fun2 is last

c is defined in fun2

d is define in fun2

e is defined in fun2

f is visible from fun3

b is visible from fun1

a is visible from main

User Rjanjic
by
4.1k points