What are the values if different types of scoping are used i
What are the values if different types of scoping are used in this program ?
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
Question a : Suppose dynamic scoping with shallow binding is used by the interpreter to execute this code. What is the value printed by the program?
output:: 1
question b:suppose dynamic scoping with deep binding is used by the interpreter to execute this code. What is the value printed?
output:: 1
question c: suppose static scoping is used. What is the value printed by the program?
output:: 2
