Question

In: Computer Science

procedure Example is X: Integer; procedure First is begin Put(X); -- Print X New_Line; -- Print...

procedure Example is
                X: Integer;

        procedure First is
        begin
                Put(X);                 -- Print X
                New_Line;               -- Print a newline character
        end First;

        procedure Second is
                X: integer;

                procedure Third is
                        X: Integer;
                begin -- Third
                        x := 99;
                        First;
                end Third;

        begin -- Second
                x := 88;
                Third;
        end Second;

begin -- Example 
        x := 77;
        First;
        Second;
end Example;

a) What will be printed by this program if we assume static scope?
b) What will be printed by this program if we assume dynamic scope?

Solutions

Expert Solution

static scope:

In this approach the value assigned at program begin and the value remains same in entire program:

begin -- Example 
        x := 77;  // The value of x is 77 and it remains same through out the program
        First;
   procedure First is
        begin
                Put(X);                 -- Print 77
                New_Line;               -- Print a newline character
        end First;


        Second;
 procedure Second is
 begin -- Second
                x := 88; -- The value remains same 77
                Third;

                procedure Third is
                        X: Integer;
                begin -- Third
                        x := 99;  -- The value remains same 77
 First;
   procedure First is
        begin
                Put(X);                 -- Print 77
                New_Line;               -- Print a newline character
        end First;
                end Third;
        end Second;
end Example;

Output:

77

77

Dynamic scope:

In this approach the value changed with respect to called functions.

begin -- Example 
        x := 77;  // The value of x is 77 
        First;
   procedure First is
        begin
                Put(X);                 -- Print 77
                New_Line;               -- Print a newline character
        end First;


        Second;
 procedure Second is
 begin -- Second
                x := 88; -- The value of x is 88
                Third;

                procedure Third is
                        X: Integer;
                begin -- Third
                        x := 99;  -- The value of x is 99
 First;
   procedure First is
        begin
                Put(X);                 -- Print 99
                New_Line;               -- Print a newline character
        end First;
                end Third;
        end Second;
end Example;

Output:

77

99


Related Solutions

Write a program (in Q0.c) to do the following: In main(), declare an integer x. Print...
Write a program (in Q0.c) to do the following: In main(), declare an integer x. Print the address of x (using the address-of operator). Pass x as an argument to a function void fooA(int* iptr). (Hint: can you pass x itself directly?) In fooA(int* iptr), print the value of the integer pointed to by iptr, the address pointed to by iptr, and the address of iptr itself. In the main function, following the call to fooA(...) , print the value...
Begin this discussion by first stating your intended future career. Then give an example of a...
Begin this discussion by first stating your intended future career. Then give an example of a proportion that applies to two Populations for which you would like to do a Hypothesis Test in your future career. In your Hypothesis Test you will be testing the difference between these two Population proportions. Your discussion MUST include for the two target Populations along with the Population characteristic that your proportion is measuring. As shown in the text your Null and Alternative Hypotheses...
Begin this discussion by first stating your intended future career. Then give an example of a...
Begin this discussion by first stating your intended future career. Then give an example of a mean that applies to two Populations for which you would like to do a Hypothesis Test in your future career. In your Hypothesis Test you will be testing the difference between these two Population means when the two samples are independent. Your discussion MUST include the two target Populations along with the Population characteristic that your mean is computed for, and the unit that...
Recall the linear search algorithm: procedure linear search (x: integer, a1, a2, ..., an: distinct integers)...
Recall the linear search algorithm: procedure linear search (x: integer, a1, a2, ..., an: distinct integers) i := 1 while (i ≤ n and x 6= ai) i := i + 1 if i ≤ n then location:= i else location:= 0 return location Apply the linear search algorithm to search for the number 3 in the list 1, 5, 3, 9. (a) In this application of the algorithm, what is the integer n? (b) What is the initial value...
Let M be the integer corresponding to the first letter of your last name. For example,...
Let M be the integer corresponding to the first letter of your last name. For example, if your last name begins with "A", M=1 and if your last name begins with "Z", M=26. Let k=1/M and consider the logistic equation dy/dt = k y (M - y). Construct a single figure including Title "Logistic Equation Slope Field and Euler's Method solutions by FirstName LastName" with your actual first and last names, along the top Labels for the axes a slope...
Let M be the integer corresponding to the first letter of your last name. For example,...
Let M be the integer corresponding to the first letter of your last name. For example, if your last name begins with "A", M=1 and if your last name begins with "Z", M=26. Let k=1/M and consider the logistic equation dy/dt = k y (M - y). Construct a single figure including Title "Logistic Equation Slope Field and Euler's Method solutions by FirstName LastName" with your actual first and last names, along the top Labels for the axes a slope...
in java please: Given any integer, print an English phrase that describes the integer (e.g. “One...
in java please: Given any integer, print an English phrase that describes the integer (e.g. “One Thousand, Two Hundred Thirty Four”). An ArrayList must be used in your program.
Begin this discussion by first stating your intended future career. Then give an example from your...
Begin this discussion by first stating your intended future career. Then give an example from your intended future career of a Population Mean that you would like to do a Hypothesis Test for. The target Population of your Hypothesis Test activities must be included in your discussion along with the unit of measurement that you are using. As shown in the text your Null and Alternative hypothesis MUST include the symbol for a Population Mean along with your hypothesized claimed...
List the operating procedure to put the differential pressure transmitter into service and put it out...
List the operating procedure to put the differential pressure transmitter into service and put it out of service with suitable diagram.   
Write a program to read in a collection of integer values, and find and print the...
Write a program to read in a collection of integer values, and find and print the index of the first occurrence and last occurence of the number 12. The program should print an index value of 0 if the number 12 is not found. The index is the sequence number of the data item 12. For example if the eighth data item is the only 12, then the index value 8 should be printed for the first and last occurrence....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT