1,819 views

In the following procedure

Integer procedure P(X,Y);
Integer X,Y;
value x;
begin
K=5;
L=8;
P=x+y;
end


$X$ is called by value and $Y$ is called by name. If the procedure were invoked by the following program fragment

K=0;
L=0;
Z=P(K,L);

then the value of $Z$ will be set equal to

1. $5$
2. $8$
3. $13$
4. $0$

I think Error will come.

Value x ;

what it means and y is not even declared here.
I think answer will be 8
variable is not declared here, Did anyone get the value for this ??

X=call by value  hence we pass 0 ,

Y=call by name hence we pass expression or variable and evaluate every time

After passing the value as ‘0’ and name as ‘L’

P=0+L   // here L=8 ;

P=8; / return

Z=8

But how to decide which value to be taken? Why L=8 and not 0?
X is called by value simply means actual value will be used irrespective of whatever value inside the function that is 0

Y is called by name means address of var will be used so value will be changed after calling the function Y=8