Asked May 17, 2019

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[1] := 2;A[2] := 1;n := 1;mystery (A[1],A[n],n);

What will be the final values of n, A[1] and A[2] if the parameters are passed by reference?


Expert Answer

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


The function “mystery (A[1], 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

Check out a sample Q&A here.

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

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A

Q: Based on the code that I already have, please help me complete it. I am attempting to use 2 function...

A: Corrections in Program:Add a closing bracket after return statement of main.Remove the parameters fr...


Q: You need to use Eclipse to create this program.

A: Instructions for the first program:Create an array of size 5 and initialize a counter variable named...


Q: 2. Write a program called ListOddNumbers that prints the below (there is a single space between each...

A: Solution: 2. The below program is written in Java language to display the odd number between 1 and 5...


Q: do big data could replace the artistic vision of a creative director? and why?

A: Justification:“Yes”, big data replace the artistic vision of a creative director.


Q: Typically, a hospital patient receives medication that have been ordered by a particular doctor. Bec...

A: Lets write the business logic first. The business rules between PATIENT and ORDER will be.• A patien...


Q: Question: Write a program that prompts the user to enter the number of students and each student's s...

A: Solution:The python program has the following algorithm:Prompt and read the total number of students...


Q: Attached Files:  getRandomLib.h: // This library provides a few helpful functions to return rand...

A: Program Instructions:Include the necessary header files.Print hello message and as for a response.De...


Q: What is the best way to pass 2D arrays to a function? (C++) For my program, I have a 2D array (size:...

A: There are two ways to pass 2-D array to a function either by sending the array name in the function ...


Q: Write a program that coverts a zip code to a bar code. The bar codes use large and small bars. We wi...

A: Solution:#Define the functiondef checksum(zip):    #Declare the empty variable    sum = 0    #Loop e...