I am having a hard time understanding the output of this program with shadow and deep binding. Can someone explain it more in detail? I posted the answers below   x : integer – – global procedure set x(n : integer) x := n procedure print x() write integer(x) procedure foo(S, P : function; n : integer) x : integer := 5 if n in {1, 3} set x(n) else S(n) 174 Chapter 3 Names, Scopes, and Bindings if n in {1, 2} print x() else P set x(0); foo(set x, print x, 1); print x() set x(0); foo(set x, print x, 2); print x() set x(0); foo(set x, print x, 3); print x() set x(0); foo(set x, print x, 4); print x()   Here are the answers to the questions.     The program prints = 10 20 30 40 with shallow binding The program prints = 10 52 00 44 with deep binding,

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

I am having a hard time understanding the output of this program with shadow and deep binding.

Can someone explain it more in detail? I posted the answers below

 

x : integer – – global
procedure set x(n : integer)
x := n
procedure print x()
write integer(x)
procedure foo(S, P : function; n : integer)
x : integer := 5
if n in {1, 3}
set x(n)
else
S(n)
174 Chapter 3 Names, Scopes, and Bindings
if n in {1, 2}
print x()
else
P
set x(0); foo(set x, print x, 1); print x()
set x(0); foo(set x, print x, 2); print x()
set x(0); foo(set x, print x, 3); print x()
set x(0); foo(set x, print x, 4); print x()

 

Here are the answers to the questions.

 

 

The program prints = 10 20 30 40 with shallow binding

The program prints = 10 52 00 44 with deep binding,

 

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning