Question: x: integer := 10 y: integer := 20 procedure add x := x + y procedure second (P: procedure) x: integer := 2 P() procedure
x: integer := 10
y: integer := 20
procedure add
x := x + y
procedure second (P: procedure)
x: integer := 2
P()
procedure first
y: integer := 3
second(add)
// main program
first()
write integer(x)
1. What does it print if the language uses dynamic scoping with deep binding?
2. What does it print if the language uses dynamic scoping with shallow binding?
For question 1, I think it will prints out x(global)=3(local y)+10(global x)=13.
For question 2, I think it will prints out 10. I think local variable x= 2(local x)+3(local y)=5.
Am I correct? Can anyone show me how to solve this question?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
