# 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 reference?

Question
85 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 reference?

check_circle

Step 1

Call by reference

• The arguments passed to a function will copy the address of an argument into the formal parameter.
• Inside the function, the address is used to access the actual argument used in the call.
• Therefore, the changes made to the parameter will affect the arguments passed.
Step 2

Explanation:

The function “mystery (A, A[n], n)” called with arguments (2, 2, 1). The integers in the parameter, x = 2, y = 2, z = 1.

In the begin statement, z becomes 2, y becomes 4.

The parameter changes x = 2, y = 4, z =...

### 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

### Computer Science 