52.5k views
1 vote
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 fun1; fun1 calls fun2; fun2 calls fun3. b. main calls fun1; fun1 calls fun3. c. main calls fun2; fun2 calls fun3; fun3 calls fun1. d. main calls fun3; fun3 calls fun1. e. main calls fun1; fun1 calls fun3; fun3 calls fun2. f. main calls fun3; fun3 calls fun2; fun2 calls fun1.

User Defus
by
4.1k points

1 Answer

2 votes

Answer:

see explaination

Step-by-step explanation:

a) Main call fun1; fun1 calls fun2; fun2 calls fun3.

Answer:

Variables that are visible at the last function call:

a ------------- defined in main

b ------------- defined in fun1

c ------------- defined in fun2

d, e, f ------------- defined in fun3

b) Main call fun1; fun1 calls fun3.

Answer:

Variables that are visible at the last function call

a ------------- defined in main

b, c ------------- defined in fun1

d, e, f ------------- defined in fun3

c) Main calls fun2; fun2 calls fun3; fun3 calls fun1.

Answer:

Variables that are visible at the last function call:

a ------------- defined in main

e, f ------------- defined in fun3

b, c, d ------------- defined in fun1

d) Main calls fun3; fun3 calls fun1.

Answer:

Variables that are visible at the last function call:

a ------------- defined in main

e, f ------------- defined in fun3

b, c, d ------------- defined in fun1

e) Main calls fun1; fun1 calls fun3; fun3 calls fun2.

Answer:

Variables that are visible at the last function call:

a ------------- defined in main

b ------------- defined in fun1

f ------------- defined in fun3

c, d, e ------------- defined in fun2

f) Main calls fun3; fun3 calls fun2; fun2 calls fun1

Answer:

Variables that are visible at the last function call:

a ------------- defined in main

f ------------- defined in fun3

e ------------- defined in fun2

b, c, d ------------- defined in fun1

User Wladek Surala
by
4.0k points