Part 10
Parameter Modes "preserves x "
and "restores x"
In both modes the outgoing value of x will be the same at the incoming value (#x); for preserves the value value will not be changed during the execution of the operation,
but for restores it may be changed during the execution of the operation.
Operation Sum (restores I: Integer; preserves J : Integer): Integer;
ensures: Sum = (I + J);
Main program:
Var Num, Num1, Num2, IntSum : Integer;
Num := 5;
Num1 := Num + 2;
Num2 := Num + 6;
IntSum = Sum (Num1; Num2);
After Sum executes:
Num = 5; Num1 = 7; Num2 = 11; IntSum = 18;
|