Changing 2D pointer in pascal

76 views Asked by At

How can I write equivalent to this in pascal?

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

I've tried something like this:

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

In fact, I want to know how to do equivalent to this in pascal: *head = *member; where both are of struct node** type, 2D-pointer.

EDIT: I've added my pascal compiler. It might be relevant.

2

There are 2 answers

9
Elliott Frisch On BEST ANSWER

From this tutorial on pascal pointer to pointer, you could do something like this

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.
0
AudioBubble On

I think you can do a pointer to a pointer like so:

type
   ptr = ^integer;
   ptr_ptr = ^ ptr;

And then deference it like so:

ptr_ptr ^^

Therefore *head = *member; should probably look like head^^ := member^^.