我在网上找不到 ^ 运算符是什么意思。
那么 ^ 在这个例子中意味着什么:
P = PChar(s);
While P^ <> #0 do
begin
//do something
end;
例如,#0
是表示字符串结尾的字符。但我无法在互联网上找到 ^。有人可以解释一下吗?
最佳答案
它是指针取消引用运算符。在您的示例代码中, P
是指向字符的指针。因此 P^
取消引用该指针。换句话说,P^
计算出 P
指向的字符。
运算符记录在此处:Expressions | Pointer Operators .
The
^
operator dereferences a pointer. Its operand can be a pointer of any type except the generic Pointer, which must be typecast before dereferencing.
也许这里有一个对您更有用的文档主题:Pointers and Pointer Types .后一个主题更详细地介绍了指针。你也可以阅读有用的 String Types其中涵盖了对 PChar
的特殊处理。
关于Delphi运算符^,什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26059241/