# Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz = 2; y= z+x;endand consider the following code fragment: A := 2;A := 1;n := 1;mystery (A,A[n],n);What will be the final values of n, A and A if the parameters are passed by value?

Question
71 views

Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz = 2; y= z+x;endand consider the following code fragment: A := 2;A := 1;n := 1;mystery (A,A[n],n);

What will be the final values of n, A and A if the parameters are passed by value?

check_circle

Step 1

Pass by value copies the value of argument and passes it to the parameter. Hence, the final value of n, A and A will be 1, 2 and 1 respectively. Since A[n] was passed not A, its value will not change. And, any value that will change inside the procedure mystery() will have scope only to that procedure. Thus the final values will remain unchanged.

Step 2

The given problem can be tested using the following Pascal code:

var

A: array [1..2] of integer;

n: integer;

procedure mystery(x, y, z: integer);

begin

z := 2;

y := z+x;

end;

begin

A:=2;

A:=1;

n:=1;

writeln('Before calling mystery()');

&...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Programing Language 