Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given this pseudocode program, what are the correct results with the following p

ID: 3778648 • Letter: G

Question

Given this pseudocode program, what are the correct results with the following parameter passing modes?

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) end

Explanation / Answer

Pass by value
p(a,a) which means p(2,2)
here x is in and out variable means, it will have input value and it will be written as well
x = x+1
x= 2+1
x= 3
a: = 2

Hence here out value will be of x
so write_integer(a) will have 3

Now call by reference this means whatever effects are there to the passed parameters will be reflected to the original variable
p(2,2)
x will hold and y will hold 2
x = x+1;
x=3
a= y
a becomes 2

Its call by reference so a becomes 2 and write_integer(a) will have 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote