procedure parameter by VAL/VAR.
Verschil tussen Call by Value/Reference
- (D1) VAR-demo.
- (S1) Reset procedure
- (S2) Your own version of INC
- (S3) SWAP procedure.
- (S4) DIV & MOD
- (S5)
- (X1)
- (H1)
- (H2)
- (T1) Output
PROCEDURE proc1(VAR a1:CARDINAL; a2: CARDINAL):CARDINAL;
BEGIN
a1 := a2 + 7;
a2 := a2 - 7;
RETURN a1 * a2 - 4;
END proc1;
PROCEDURE proc2(b1: CARDINAL; VAR b2:CARDINAL):BOOLEAN;
VAR toReturn: BOOLEAN;
b3:CARDINAL;
BEGIN
b3 := b2;
b2 := b1 MOD b3;
b1 := b1 / b3;
IF (b3 = 0) THEN
toReturn := TRUE;
ELSE
toReturn := FALSE;
END;
RETURN toReturn;
END proc2;
VAR x1, x2, x3: CARDINAL;
BEGIN
x1 := 3;
x2 := 11;
x3 := proc1(x1, x2);
IF proc2(x3, x2) THEN
x1 := x3;
ELSE
x1 := x2;
END;
WrCard(x1, 0);
WrLn();
WrCard(x2, 0);
WrLn();
WrCard(x3, 0);
WrLn();
END T1.