I wish to understand more about parameter parsing. I have an example with the code below.
What the results if I pass parameter by:
* Value
* Reference
* Name
procedure f (x, y, z)
x := x + 1
y := z
z := z + 1
i := 0; a[0] := 10; a[1] := 11
f (i, a[i], i)
print i, a[0], a[1]
If I understood it correctly the results are:
By Value: 1, 11, 12
By Reference: 2, 12, 10
By Name: 1, 10, 0
Am I in the right direction?
I’ll give you a partial answer
when you pass by value, you pass a copy of your variable, so your variable can’t be changed by the function.
so the answer of by value should be 0,10,11 which are the initial values of i, and the array.
when you pass by reference it will change your values :
the first line will change i to 1;
the second line will change a[0] to 1;
the third line will change i to 2;
which means it will print 2,1,11
i never herd about passing by name.
hope it helps