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 are 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 f1 which calls f2. (Assume that f1 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 f1(); void f2(); int a, b, c; int main() {    int c, d;    … // Line 1 } void f1() {   int b, e;   if (…) { int a, b;    // Line 2   }   …  // Line3 } void f2() {    int b, d;    if (…) { 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 f1), c (global), e (declared in f1)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 9SA
icon
Related questions
Question
  1. 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 are 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 f1 which calls f2. (Assume that f1 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 f1();

void f2();

int a, b, c;

int main()

{

   int c, d;

   … // Line 1

}

void f1()

{

  int b, e;

  if (…) {

int a, b;

   // Line 2

  }

  …  // Line3

}

void f2()

{

   int b, d;

   if (…) {

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 f1), c (global), e (declared in f1)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning