7.3.1 How it works
Since the subprogram receives a variable and not a value, the argument must be a designator of the exact type: a variable, a cell or an attribute. A literal or an operation will not do.
The typical use is returning more than one result:
ProgramTwo results by reference
Subroutine Dividir(a As Integer, b As Integer, cociente As Integer By Reference, resto As Integer By Reference)
cociente <- a Div b;
resto <- a Mod b;
EndSubroutine
Algorithm Principal
Define c, r As Integer;
Dividir(17, 5, c, r);
Write c, " ", r;
EndAlgorithmOutput
3 2
The program finishes normally.
cociente and resto have no box of their own: they are arrows to c and r. Assigning to them fills the caller's boxes.On the left, the main boxes c and r with 3 and 2. On the right, Dividir with cociente and resto, which are arrows to c and r.
c and r had no value before the call, and that is not an error: the engine sees that Dividir gives them a value before reading them on every path. Those parameters are output parameters. If the subprogram read the parameter before assigning it, the argument would have to arrive with a value.
In short
By Referenceshares the caller's variable.- The argument must be a designator of the exact type.
- It is used to return several results.
- If the subprogram assigns before reading, the argument may arrive without a value.