You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.2 KiB
Plaintext
32 lines
1.2 KiB
Plaintext
{ Example from the lab pdf }
|
|
PROGRAM arrparmechanism;
|
|
|
|
VAR a : ARRAY [0 .. 5] OF integer; {array with values a[0], a[1], a[2], a[3], a[4], a[5]}
|
|
VAR b : ARRAY [1 .. 6] OF integer; {array with values b[1], b[2], b[3], b[4], b[5], b[6]}
|
|
|
|
PROCEDURE arrcopy(VAR dest : ARRAY [0 .. 5] OF integer; src : ARRAY [5 .. 10] OF integer);
|
|
{dest is a var-paremeter, src is a value-parameter. Note the funny array bounds!}
|
|
VAR i : integer;
|
|
BEGIN
|
|
i := 0
|
|
; WHILE i <> 6 DO
|
|
BEGIN
|
|
dest[i] := src[i+5] { reflected to caller: dest is a var-parameter!}
|
|
; src[i+5] := 0 { not reflected to caller: src is a value-parameter!}
|
|
; i := i + 1
|
|
END
|
|
END;
|
|
|
|
FUNCTION sum(a : ARRAY [1 .. 3] OF integer) : integer;
|
|
BEGIN
|
|
sum := a[1] + a[2] + a[3]
|
|
END;
|
|
|
|
BEGIN
|
|
readln(b[1], b[2], b[3], b[4], b[5], b[6])
|
|
; arrcopy(a,b) {here index range translation takes place, the range sizes fit }
|
|
; writeln(a[0],a[1],a[2],a[3],a[4],a[5]) {this will print: 1 2 3 4 5 6 }
|
|
; writeln(b[1],b[2],b[3],b[4],b[5],b[6]) {this will also print: 1 2 3 4 5 6 }
|
|
; writeln(sum(a[0..2])) { note the section notation: this will print 6 (because 1+2+3=6) }
|
|
; writeln(sum(a[1..3])) { note the section notation: this will print 9 (because 2+3+4=9) }
|
|
END. |