program main(); Assume parameters are passed by value
var A,B: integer;
procedure one(X,Y: integer);
procedure two(A: integer);
begin
B := B + A;
end;
begin
if (X = 1) then two(Y);
else begin B := B + 1; one(X-1,Y); end;
L1: end;
begin
A := 3; B := A+1;
one(A,B);
L0: write(B);
end.
First activation is for main. Last activation is for two. The three in the middle are for one.
10 get printed out
program main();
var A,B: integer;
procedure new(B,C : integer);
begin
B := B + C; C := 5;
write(A,B,C);
end;
begin
A := 3; B := 4;
new(A,B);
write(A,B);
end.
What five values get printed out if the parameters are passed
3 7 5 3 4
7 7 5 7 5
3 7 5 7 5
# elements = (5-1+1)*(4-0+1)*(8-2+1) = 5 * 5 * 7 = 175 total size = #elements * size = 175*2 = 350
Compute the strides:
d3 = 2 (base element size)
d2 = # elements in dimension 3 * d3 = 7 * 2 = 14
d1 = # elements in dimension 2 * d2 = 5 * 14 = 70
address = 100 + (3 - 1)*70 + (2 - 0)*14 + (5 - 2)*2
= 100 + 140 + 28 + 6 = 274
Since the base address is 100 and the element size is 2, this must be the 15th element of the array. You can count this out or find values (in range for the given dimension) that fit the equation: 130 = 100 + (i - 1)*70 + (j-0)*14 + (k-1)*2 30 = (i-1)*70 + (j-0)*14 + (k-1)*2 i = 1, j = 2, and k = 2 work here. A[1][2][2]