In the following procedure Integer procedure P(X, Y); Integer X,Y: value x;…

2020

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 Z would be set equal to

  1. A.

    5

  2. B.

    8

  3. C.

    13

  4. D.

    0

Attempted by 48 students.

Show answer & explanation

Correct answer: B

The procedure P passes X by value and Y by name. When invoked with K=0 and L=0, X receives a copy of 0. Y refers directly to the caller's variable L.

Inside the procedure, L is assigned 8. Since Y is passed by name, this assignment updates the caller's L to 8.

The result P = x + y becomes 0 + 8, so Z is set equal to 8.

Explore the full course: Isro