zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    提示“此Flash Player与您的地区不相容,请重新安装Flash”的解决办法
    python中安装并使用redis
    linux安装flash player来播放视频
    安装redis
    centos6.5安装无线网卡驱动并配置wifi
    centos安装java的jdk
    001-python简介
    源码
    进程间通信之综述
    图的概念
  • 原文地址:https://www.cnblogs.com/GodPan/p/3390071.html
Copyright © 2011-2022 走看看