The following questions refer to the skeletal C program show
The following questions refer to the skeletal C++ program shown below. (a) Assume that static scoping is used. List all variables, along with the functions in which they are declared, that are visible at Line 1 in the program. (b) Repeat part (a), but list the variables that arc visible at Line 2. (c) Repeat part (a), but list the variables that are visible at Line 3. (d) Repeat part (a), but list the variables that are visible at Line 4. (e) Repeat part (a), but list the variables that are visible at Line 5. (f) Assume that dynamic scoping is used, and that main calls F_1, which calls f_2. (Assume that f_1 calls f_2 on Line 3.) List all variables, along with the functions in which they are declared, that are visible at Line 5 in the program. void f1(); void f2(); int a, b, c; int main () int c, d; -//Line 1) void f1() {int b, e; if (_) (int a, b; _//Line 4)_//Line 3 void f_2 () (int b, d; iI (_) (int a. d; -//Line 4}_//Line 5} A sample answer to one part of the problem might look like this: a (global), b (declared in if block in f 1), c (global), e (declared in f1)
Solution
a) a(global),b(global), c( declared in main),d(declared in main)
b) a(global),b(declared in if block),c (global),e(declared in f1)
c) a(global),b(declared in fi()),c (global),e(declared in f1)
d) c(global),a(declared in if block),d(declared in if in f2()),b(declared in f2)
e)c(global),a(global),d(declared in f2()),b(declared in f2)
f) c( declared in main),d(declared in if in f2()),a(delcared in if in f2()),b(declared in f2()),e(declared in f1())
