httpsiimgurcomIXoKzdbpng The following questions refer to th

https://i.imgur.com/IXoKzdb.png

The following questions refer to the skeletal C++ program shown below. 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. Repeat part (a), but list the variables that are visible at Line 2. Repeat part (a), but list the variables that are visible at Line 3. Repeat part (a), but list the variables that are visible at Line 4. Repeat part (a), but list the variables that are visible at Line 5. Assume that dynamic scoping is used, and that main calls fl, which calls f2. (Assume that fl calls f2 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 fl (); void f2(); int a, b, c; int main() {int a, b, d; ...//Line 1} void fl() {int d, e; if (...) {int a, b; ...//Line 2} ...//Line 3} void f2() {int a, c; if (...) {int b, c; ...//Line 4} ...//Line 5} Here\'s an example of the format that you should use for your answers: a (global), d (declared in fl), e (declared in if block in fl)

Solution

Please find the answers below :

7.a)

Visibility at Line 1 :

a (declared in main), b (declared in main), d (declared in main), c (declared as global)

Here a and b variables in main function will overides the value of globallly declared a and b.

7.b)

Visibility at Line 2 :

a (declared in if block in f1), b (declared in if block in f1), d (declared in f1), e (declared in f1), c (declared as global)

Here a and b variables declared in if block in f1 will overrides the globally declared a and b.

7.c)

Visibility at Line 3 :

a (declared as global), b (declared as global), c (declared as global) d (declared in f1), e (declared in f1)

Here a and b variables declared in if block in f1 will not be visible outside the if block, thus the globally declared a and b will take the over here.

7.d)

Visibility at Line 4 :

b (declared in if block in f2), c (declared in if block in f2), a (declared in f2)

Here b and c variables declared in if block in f2 will overrides the globally declared a and b, and locally declared c in f2.

7.e)

Visibility at Line 5 :

a (declared in f2), b (declared as global), c (declared in f2)

Here b and c variables declared in if block in f2 will not be visible outside the if block, thus the globally declared b will take the over here, but c will be the one declared in f2.

7.f)

a (declared in f2), b (declared as global), c (declared in f2), d (declared in main)

https://i.imgur.com/IXoKzdb.png The following questions refer to the skeletal C++ program shown below. Assume that static scoping is used. List all variables, a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site