Delphi多级指针


本文整理自网络,侵删。

 

要点:
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加载图像存储到数据库中

Delphi sqlite 简明上手指南

Delphi分割字符串的函数--extractstrings

Delphi安卓创建pdf文件并打开

Delphi 根据快捷方式路径取源文件地址

datasnap服务器如何得到客户端的ip和端口

Delphi inc函数和dec函数的用法

Delphi 时间差函数及部分字符串与日期时间相互转换的函数

Delphi-dbgrid取得所有表中的值

Delphi xe3里判断网络是否连接成功

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...