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 value?

Question
Asked May 14, 2019
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[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 value?

check_circle

Expert Answer

Step 1

Pass by value copies the value of argument and passes it to the parameter. Hence, the final value of n, A[1] and A[2] will be 1, 2 and 1 respectively. Since A[n] was passed not A[2], 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[1]:=2;

     A[2]:=1;

     n:=1;

     writeln('Before calling mystery()');

  &...

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

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

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

Q: Create a recursive store function called add_numbers to calculate the total of all consecutive posit...

A: As there is no specific programming language mentioned, so we are creating this program in C program...

question_answer

Q: A Maze Room : In this lab, we will make a maze game. The maze is based on Linked Lists. Instead of h...

A: For class Room, implement the setter and getter methods by assign and returning values respectively....

question_answer

Q: Write a PL/SQL block to retrieve and display the students enrolled in a course.

A: Click to see the answer

question_answer

Q: Choose an organization that you interact with regularly and list as many different “systems” (comput...

A: Let’s break the system of university part by part. For example, it may include course management and...

question_answer

Q: One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of ...

A: The algorithm for the program is as follows:Accept input string as the square feetCalculate the numb...

question_answer

Q: Write a program called StudentTable that prints the below table. Use only print() orprintf(). DO NOT...

A: The program in Java would be using print and printf statements with formatting for left alignment of...

question_answer

Q: Develop the ‘Shape’ application such that: ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit f...

A: Program plan:Define a class named “Shape”.Define a default constructor to print constructor invoked ...

question_answer

Q: Visual Basic. Given two variables, isEmpty of type boolean, indicating whether a class roster is emp...

A: We will have two check the below conditions:-1) class roster is not empty2) the class is one or thre...

question_answer

Q: Write a function for the Superman ride at Six Flags that determines whether the user is taller than ...

A: Program code to write a function for the Superman ride  to determines whether the user is taller tha...