Consider the following pseudocode program sum integera globa

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: = x adder(x)//invoke procedure that was passed as argument write_integer(sum) begin//main program sum: = 0 p(1, add) end Suppose dynamic scoping with shallow binding is used by the interpreter to execute this code. What is the value printed by the program? Suppose dynamic scoping with deep binding is used by the interpreter to execute this code. What is the value printed? Suppose static scoping is used. What is the value printed by the program?

Solution

a)
shallow binding will have scope of procedure P. So it prints the value 0.

b)
In deep binding, the scope will be in add procedure, so we are adding to 1 to sum, so it outputs 1.

c)
In static binding, the scope will be in procedure p only. It won\'t change even though we change in other
function. So result will be 0.

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site