Pointer to an array of pointers in Pascal

1.5k Views Asked by At

I don't know how to access the content of an array of pointers by a pointer. Here's an example:

Type
    PInteger = ^Integer;
    IntegerArrayP = array of PInteger;
    PIntegerArrayP = ^IntegerArray;

var
    variable: Integer;
    parrp: PIntegerArrayP;
    arrp: IntegerArrayP;
begin
    SetLength(arrp, 5);
    parrp := @arrp;
    For variable := Low(arrp) to High(arrp) do
    begin
        arrp[variable] := New(PInteger);
        (parrp^)[variable]^ := variable;
        WriteLn('parrp: ', arrp[variable]^);
    end;
end.

In my opinion it should be done like this (ptabp^)[variable]^ := variable; But I guess I'm wrong.

1

There are 1 best solutions below

3
On BEST ANSWER

You are right. Parens might be omitted.
What pascal compiler do you use? Proper usage of New routine:

 New(arrp[variable]) ;
 parrp^[variable]^ := variable;

P.S. Do you really need these pointer types here?

P.P.S. Now I see an error: PIntegerArrayP = ^IntegerArrayP;