Consider the following skeletal C program: 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; . . . } 256 Chapter 5 Names, Bindings, and Scopes 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

Respuesta :

Answer:

Check the explanation

Explanation:

a) main calls fun1; fun1 calls fun2; fun2 calls fun3

fun3()                                        d, e, f

fun2()                                        c, d, e

fun1()                                        b, c, d

main()                                        a, b,c

CALL STACK SHOWING THE VARIABLES OF EVERY FUNCTION

   From the above call stack diagram, it is very clear that the last function call is made to fun3().

   In fun3(), the local variables "d, e, f" of fun3() will be visible

   variable "c" of fun2() will be visible

   variable "b" of fun1() will be visible

   variable "a" of main() will be visible

b) main calls fun1; fun1 calls fun3

fun3()                                        d, e, f

fun1()                                        b, c, d

main()                                        a, b,c

CALL STACK SHOWING THE VARIABLES OF EVERY FUNCTION

   From the above call stack diagram, it is very clear that the last function call is made to fun3().

   In fun3(), the local variables "d, e, f" of fun3() will be visible

   variable "b, c" of fun1() will be visible

   variable "a" of main() will be visible

c) main calls fun2; fun2 calls fun3; fun3 calls fun1

fun1()                                        b, c, d

fun3()                                        d, e, f

fun2()                                        c, d, e

main()                                        a, b,c

CALL STACK SHOWING THE VARIABLES OF EVERY FUNCTION

   From the above call stack diagram, it is very clear that the last function call is made to fun1().

   In fun1(), the local variables "b, c, d" of fun1() will be visible

   variable "e, f" of fun3() will be visible

   variable "a" of main() will be visible

d) main calls fun1; fun1 calls fun3; fun3 calls fun2

fun2()                                        c, d, e

fun3()                                        d, e, f

fun1()                                        b, c, d,

main()                                        a, b,c

CALL STACK SHOWING THE VARIABLES OF EVERY FUNCTION

   From the above call stack diagram, it is very clear that the last function call is made to fun2().

   In fun2(), the local variables "c, d, e" of fun2() will be visible

   variable "f" of fun3() will be visible

     variable "b" of fun1() will be visible

   variable "a" of main() will be visible

The last function called will comprise of all its local variables and the variables other than its local variables from all its preceding function calls till the main function.