ISRO Scientist/Engineer CSE 2020Programming in C › Not yet assigned to a topic
ISRO Scientist/Engineer CSE 2020 PYQ: 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…
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
- A5
- B8Correct answer
- C13
- D0
Answer
(B) $8$
Approach
The procedure P has parameters X (call by value) and Y (call by name). The call P(K, L) passes the value of K (which is 0) to X, and passes the name L to Y. Inside P, the assignment P = x + y is executed. Since X is call by value, x is 0. Since Y is call by name, y is evaluated as the current value of L, which is 8. Thus P becomes 0 + 8 = 8, and this value is returned and assigned to Z.
Reviewed by ISRO IQ Editorial Team.