本文整理自网络,侵删。

要点:1.指针指向的地址或许不一样,也不管指针是多少级的指针,他们指针本身都是一样的,都可以用PInteger来强转换。2.多级指针取地址,要用多个^,比如二级指针,需要PInteger(MyPint2^)^来取值
program MyPoint; //指针详解{$APPTYPE CONSOLE}uses SysUtils,windows,Generics.Collections ;
{多级指针}procedure MyFunc2();var MyInt : Integer;//整数 MyPint1 : PInteger; //1级指针 MyPint2 : ^Integer;//2级指针 MyPint3 : ^Integer; //3级指针begin{指针赋值} MyInt := 100; MyPint1 := @MyInt;//指针 Writeln('Mypint1^为:',Mypint1^);{二级指针赋值} MyPint2 := @MyPint1;//指针的指针,指向这个指针 PInteger(MyPint2^)^ := PInteger(MyPint2^)^ + 10;//赋值 Writeln('PInteger(MyPint2^)^为:',PInteger(MyPint2^)^);{三级指针赋值} MyPint3 := @MyPint2; PInteger(PInteger(MyPint3^)^)^ := PInteger(PInteger(MyPint3^)^)^ + 20 ; Writeln('PInteger(PInteger(MyPint3^)^)^为:',PInteger(PInteger(MyPint3^)^)^); Writeln('一级指针:' + InttoHex(Integer(MyPint1),8),'二级指针:'+InttoHex(Integer(MyPint2),8),'三级指针:'+InttoHex(Integer(MyPint3),8)); //输出内容end;
{main主函数}begin MyFunc2(); Readln;//回车退出end.https://www.cnblogs.com/GodPan/p/3390071.html
相关阅读 >>
Delphi分割字符串的函数--extractstrings
Delphi 时间差函数及部分字符串与日期时间相互转换的函数
更多相关阅读请进入《Delphi》频道 >>