An array of pointers pointing to the same array

I read the Delphi code snippet as follows:

sample1  = ARRAY[1..80] OF INTEGER; 
psample =^sample1;

VAR
  function :ARRAY[1..70] OF psample;

From my point of view, the programmer is trying to declare an array containing 70 pointers, and each pointer points to the array sample1.

So when I write:

function[1]^[1] := 5;
function[1]^[2] := 10;

then:

function[n]^[1] := 5 
function[n]^[2] := 10; ( n = 2 to 70)

Is it correct?

+5
source share
2 answers

There is no information in your sample code because you are not saying how it is defined function. This means that you cannot draw the conclusions that you are trying to draw.

Of course, since it functionis a reserved word in Pascal, this code could never even compile. Suppose now that the variable is called f.

Consider the following definitions:

type
  sample1 = array [1..80] of integer; 
  psample = ^sample1;

var
  f : array [1..70] of psample;

sample1 psample . sample1 - , 80 . psample sample1.

f. 70 psample s.

, , , f[1]^[1], f.

, :

var
  sample: sample1;
...
for i := 1 to 70 do
  f[i] := @sample;

, f[i]^[k] , f[j]^[k] i j. , f[1]^[1] := 42, f[2]^[1], f[3]^[1] ..

, :

var
  samples: array [1..70] of sample1;
...
for i := 1 to 70 do
  f[i] := @samples[i];

f[i] . f[1]^[1] := 42 f[2]^[1] .

+6

. 70 , 80 .

+2

All Articles