Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. The following questions refer to the skeletal C++ program shown below. (a) As

ID: 3758034 • Letter: 5

Question

5.   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)   epeat part (a), but list the variables that are visible at Line 2.
(c)   epeat part (a), but list the variables that are visible at Line 3.
(d)   epeat 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 f1, which calls f2, which
calls f3. (Assume that f2 calls f3 on Line 4.) 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();
void f3();
int a, b, c; int main()
{
int b, d;
…   // Line 1
}

void f1()
{
int b, d;
…   // Line 2
}

void f2()
{
int c, e; if (…) {
int b, c, d;
…   // Line 3
}
…   // Line 4
}

void f3()
{
int b, f;
…   // Line 5
}

A sample answer to one part of the problem might look like this:

a (global), c (declared in f2), d (declared in if block in f2)

Explanation / Answer

Static Scoping: Once the global variable is assigned a value it's scope will exist throughoutthe program execution.

Dynamic Scoping: Irrespective of the value of global variable .The value assigned in the block is considered.

Line 1 : a (Global Variable), b ( declared inside the f1(),f2(),f3() and main() ), c (declared in f2(), if block of f2), d (d declared in the if block in f2), e (declared in f2()), f (declared in f3())

Line2:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote