(Solved):Consider the following pseudo-code program: sum : integer // a global variable procedure add(amount : integer) # sum := sum + amount procedure p(x : integer, adder : procedure) # integer sum # sum… View Answer…

 

Question

Consider the following pseudo-code program:

sum : integer // a global variable

procedure add(amount : integer)

  1. sum := sum + amount

procedure p(x : integer, adder : procedure)

  1. integer sum
  2. sum := x
  3. adder (x) // invoke procedure that was passed as argument
  4. write_integer(sum)

begin // main program

  1. sum := 0
  2. p(1, add)

end

a. Suppose dynamic scoping with shallow binding is used by the interpreter to execute this code. What is the value printed by the program?

b. Suppose dynamic scoping with deep

Scroll to top