在pascal中更改2D指针

时间:2013-12-20 18:31:18

标签: c windows pointers pascal fpc

我怎样才能在pascal中写出相同的内容?

void push(struct node **head, struct node **member)
{
  (*head)->next = *member;
  (*member)->prev = *head;
  (*member)->next = NULL;
  *head = *member;
}

我尝试过这样的事情:

procedure Push(head : nodeptr; prev : nodeptr; sym : nodeptr);
begin
    prev^.prev := sym;
    sym^.prev := prev;
    sym^.next := nil;
    prev := sym;
end;

事实上,我想知道在pascal中如何做到这一点:*head = *member;其中两者都是struct node**类型,2D指针。

编辑:我添加了我的pascal编译器。这可能是相关的。

2 个答案:

答案 0 :(得分:2)

在pascal pointer to pointer的本教程中,你可以做这样的事情

program exPointertoPointers;
type
  iptr = ^integer;
  pointerptr = ^ iptr;
var
  num: integer;
  ptr: iptr;
  pptr: pointerptr;
  x, y : ^word;
begin
  num := 3000;
  (* take the address of var *)
  ptr := @num;
  (* take the address of ptr using address of operator @ *)
  pptr := @ptr;
  (* let us see the value and the adresses *)
  x:= addr(ptr);
  y := addr(pptr);
  writeln('Value of num = ', num );
  writeln('Value available at ptr^ = ', ptr^ );
  writeln('Value available at pptr^^ = ', pptr^^);
  writeln('Address at ptr = ', x^); 
  writeln('Address at pptr = ', y^);
end.

答案 1 :(得分:1)

我认为你可以像这样指针指针:

type
   ptr = ^integer;
   ptr_ptr = ^ ptr;

然后顺从它:

ptr_ptr ^^

因此*head = *member;应该看起来像head^^ := member^^