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...
Give the value of x (x is an integer and assume integer arithmetic for all operations)....
Give the value of x (x is an integer and assume integer arithmetic for all operations). ________ 1.             x = 12 - 4 * 2 - 8; ________ 2.             x = 24 / 2 + 1 * 4; ________ 3.             x = 12 - 9 + 4 * 2 + 3 ^ 4; ________ 4.             x = 24/(3 + 2) * 4; ________ 5.             x = 2 * (5 - 3) + 7; ________ 6.             x = 12 - (15/5...
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif...
X=5,Y=7,Z=10 A. if(X<Y): print "LESS" else: print "OTHER" B. if (x == 1): print "ONE" elif (x == 2): print "TWO" elif (x == 3): print "THREE" elif (x == 4): print "FOUR" elif (x == 5): print "FIVE" elif (x == 6): print "SIX" else: print "OTHER" C. if (X<Z): print X X = X + 1 D. while (X<Z): print X X = X + 1 Q11. What is the final value of X in D Q12. Is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT