What is the value printed by the following pseudo-code program for each of the f
ID: 3776594 • Letter: W
Question
What is the value printed by the following pseudo-code program for each of the four parameter passing modes call-by-value, call-by-reference, call-by- value/result, and call-by-name? That is, for each of the four parameter passing modes assume that both the x and y parameters use that mode. Show how each program is evaluated in that mode and show the final value printed: a: integer//a global variable procedure p(in out x: integer, in y: integer) x: = x + 1 a: = y begin//main program a: = 2 p(a, a) write integer(a) endExplanation / Answer
call by value
a=2
p(2,2)
x=2+1 = 3
a = 2
result : 2
call by refrence
a=2
p(refrence of a,refrence of a)
x= 2+1 = 3
a = 3
result : 3
call by value result
a=2
p(a,a)
x= 2+1 = 3
a = 2
result : 3
call by name
a=2
p(a,a)
x=2+1 = 3
a=2
result : 2
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.