• 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.
  • 相关阅读:
    JAVA将list转化为xml文件
    Hibernate 配置文件属性之 级联操作cascade 性能优化inverse
    Hibernate 一对多关系操作
    Hibernate 原生SQL操作
    Hibernate 之 Criteria
    Hibernate HQL查询
    Hibernate使用getCurrentSession() 的配置
    Hibernate 主键生成策略
    hibernate(一)--简单示例
    适配器模式
  • 原文地址:https://www.cnblogs.com/GodPan/p/3390071.html
Copyright © 2020-2023  润新知