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.

 

posted @ 2013-10-26 22:26  GOD攀  阅读(366)  评论(0编辑  收藏  举报