What does caret dot (^.) mean?

穿精又带淫゛_ 提交于 2021-02-07 14:39:42

问题


What does the below Pascal code mean?

p^.rlink=q
q^.llink=p

回答1:


The pascal operator ^. is similar to operator -> in C and C++.

It dereferences the pointer (in your case, p should be defined as var p: ^type) and accesses a variable in the record, in this case, rlink and llink.




回答2:


When caret (^) appears after a pointer variable it dereferences the pointer, that is, it returns the value stored at the memory address held by the pointer. So in your case I suppose that p is a pointer to a record that has rlink property and q is a pointer to a record that has llink property. These properties are also pointers to the same structure, because p and q are then assigned to them. I suppose that this structure represents a binary tree data type with left and right nodes.




回答3:


A likely possibility is that p and q are elements in a doubly-linked list, often called a bi-directional linked list. Those two statements are attaching them together, with p on the "left" and q on the "right". An equivalent in C/C++ would be:

p->rlink = q;
q->llink = p;



回答4:


The ^'s follow a pointer, and the . access a member of a record. So these lines are probably rearranging the links in a graph of some kind.




回答5:


p and q appear to be pointers. They point to a record variables which have respectively (or probably both), a rlink and llink (guessing right link and left link).

This snippet is probably used in the context of a graph or maybe a linked list of sorts.

The caret (^) operator, in Pascal, is the dereference opertator which enables one to access the variable content not the the pointer.

The direct equivalent in C language would be

(p*).rlink=q
(q*).llink=p

but of course this would typically be expressed as

p->rlink=q
q->llink=p

with C's -> operator which does a deferencing and member access in one step.



来源:https://stackoverflow.com/questions/1814922/what-does-caret-dot-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!