Question

For the given program determine what is printed after each write statement assuming static scoping, deep...

For the given program determine what is printed after each write statement assuming static scoping, deep binding and parameters are passed-by-value-result.

program main;
   var X: integer;
   procedure Q(var I: integer; function R(J: integer):integer);
            var X: integer;
            begin
             X:=4;
             write(“In Q, before call of R, I=”, I, “X=”, X);
             I=R(I);
             write(“In Q, after call of R, I=”, I, “X=”, X);
          end;
       procedure P;
           var I: integer;
           function F(K: integer):integer;
              begin
              X:=X+K;
              F:=I+K;
              write(“In F, I=”,I, “K =”, K, “X=”,X);
             end;
         begin;
           I:=2;
         Q(X, F);
           write(“In P, I=”, I, “X=”, X);
        end;
begin
X:=7;
P;
write(“In Main, “X=”,X);
end.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
For the given program determine what is printed after each write statement assuming static scoping, deep...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following program in a C-like syntax, what does F1(m) return assuming static scoping and...

    Given the following program in a C-like syntax, what does F1(m) return assuming static scoping and dynamic scoping? You can assume that expressions are evaluated from left to right. int m = 3; int F1(int i) { return (i + F2(m) + m); } int F2(int j) { j++; return (j * m); } int main() { int m = 5; F1(m); } Explain in details how you got the answers to earn full credit. Don't just write the answer....

  • Consider the following pseudocode which uses dynamic scoping. What does the program print if the language...

    Consider the following pseudocode which uses dynamic scoping. What does the program print if the language uses shallow binding? What does it print with deep binding? x: integer//global procedure print_x write_integer (x) procedure first x:= x * 3 procedure second (F: procedure) x: integer x: = 5 F () print_x () x: = 7 second (first) print_x ()

  • 3- (3 pts) Consider the following Pascal program skeleton program main var a, b, c: integer;...

    3- (3 pts) Consider the following Pascal program skeleton program main var a, b, c: integer; procedure Sl; var x, b, c: integer procedure S2; var n, m, k: integer; end; end; procedure S3; var x, a, l: integer; end; end; List all of the variables, along with the program units where they are declared, that are visible in the bodies of S1, S2, and S3, assuming static scoping.

  • Given the following Ada program: procedure Main is X, Y: Integer; procedure Sub1 is Y, Z:...

    Given the following Ada program: procedure Main is X, Y: Integer; procedure Sub1 is Y, Z: Integer; begin -- of Sub1 point 1 Sub2; end; -- of Sub1 procedure Sub2 is X: Integer; procedure sub3 (B: Integer) is W: Integer; begin -- of Sub3 point 2 end; -- of Sub3 begin -- of Sub2 point 3 Sub3 (X); end; -- of Sub2 begin -- of Main point 4 Sub1; end; -- of Main For each of the four marked points,...

  • 8. (10%) Consider the following JavaScript program: // The main program var x,y; function f10{ var...

    8. (10%) Consider the following JavaScript program: // The main program var x,y; function f10{ var y, z; function f20{ var x, Z, P; function f30{ var x, z, ; Assume that the execution of this program is in the following unit order: main calls f3, f3 calls f1, f1 calls 12. a) Assuming that static scoping is in effect, indicate which version of each of the following variables will be visible in f2 by filling in each blank with...

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • Exercise #1: Write a C program that contains the following steps (make sure all variables are...

    Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. Commenting out the existing coding, write the code to divide a...

  • (17) (1 mark) What is the static parent of a subprogram? (18) (1 mark) What is...

    (17) (1 mark) What is the static parent of a subprogram? (18) (1 mark) What is a formal parameter? (19) (3 marks) Consider the following program, written in a C-like lan- guage int x void f(int a) {а- а+2; х %3D х+1;} void main x 1 f(x); printf("x= d\n",x); What value ot xwill be printed by the main program under each of the tollowing conditions? Imagine that tformal parameter a of function fis being passed: i by value ii. by...

  • **Program must compile under Ubuntu! (35 pts) Write a C++ program A4p2.cpp with a class of...

    **Program must compile under Ubuntu! (35 pts) Write a C++ program A4p2.cpp with a class of your own design. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called playthat should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var...

  • Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers...

    Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT