Languages differ greatly in how they handle arrays. In this question
we will focus on one issue with arrays: what happens when one array is
assigned to another (assuming the two arrays are of compatible types).
Consider, for example, two variables declared as follows in
MYSTERY syntax:
VAR a: ARRAY[1 TO 5] OF INTEGER;
VAR b: ARRAY[1 TO 5] OF INTEGER;
BEGIN ... END;
What happens when we have an assignment a := b?
If the assignment is "by reference" (which is how Java works),
variables of array type are
represented as pointers and the outcome of the assignment is that
a ends up
pointing to the same array that b points to (i.e., alias). If the
assignment is "by value" (which is how Modula-3 works), then the
assignment copies the contents of array b to array
a.
- Use this link
to figure out if
MYSTERY uses array assignment by
reference or by value. Your answer to this question should describe
which one MYSTERY uses and
also provide the evidence that enabled you to come to your conclusion.
You submissions may execute up to a total of 6 PRINT statements.
Additional attempts will be charged at 5% of this question's points per
executed PRINT.
- Discuss the relative advantages and disadvantages of array assignment by
value and array assignment by reference. Refer to the "Characteristics"
(i.e., first column) in Table 1.1 of Sebesta in your arguments.