recategorized by
2,263 views
19 votes
19 votes

What is printed by following program, assuming call-by reference method of passing parameters for all variables in the parameter list of procedure P?

program     Main(inout, output);
var     a, b:integer;
        procedure P(x, y, z:integer);
        begin
            y:=y+1
            z:=x+x
        end P;
begin
    a:=2; b:=3;
    p(a+b, a, a);
    Write(a)
end.
recategorized by

1 Answer

Best answer
24 votes
24 votes
let variable "$a$" has address $100$  and "$b$" has $200$ .

and a variable in which "$a+b$" is stored has address $300$.

now $p(300,100,100)$  which represent $x,y,z$

$y:=y+1$  // it makes $a=3$;

$z:=x+x$ //  x means the value contained at address $300$ i.e. $5$

$5+5 =10$  hence value at address $100$ i.e.  variable "$a$" will get the value $10$ .

Hence the value of $a$ i.e. $10$ will be printed.
edited by
Answer:

Related questions

22 votes
22 votes
3 answers
4