c++ - 指向Delphi中指针的指针

标签 c++ delphi pointers

如何在 Delphi 中编写此代码(C++:指向指针的指针)?

   int  var;
   int  *ptr;
   int  **pptr;

   var = 3000;
   ptr = &var;
   pptr = &ptr;

   cout << "Value of var :" << var << endl;
   cout << "Value available at *ptr :" << *ptr << endl;
   cout << "Value available at **pptr :" << **pptr << endl;

最佳答案

你可以这样做

var
  i: Integer;
  pi: PInteger;       // or ^Integer
  ppi: ^PInteger;     // or PPInteger, if you first define `type PPInteger = ^PInteger`
begin

  i := 3000;
  pi := @i;
  ppi := @pi;

  Writeln('Value of i: ', i);
  Writeln('Value of i: ', pi^);
  Writeln('Value of i: ', ppi^^); 

关于c++ - 指向Delphi中指针的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18044693/

相关文章:

c++ - 如何使用 OpenGL 加载 8 位 bmp?

delphi - Delphi 的代码片段?

delphi - 未找到 TeEngine.pas

更改为指针运算

c++ - 编译和链接时,不同的 C/C++ 模块之间有什么通信?

c++ - C++中的堆损坏错误

language-agnostic - 您是否遇到过三层间接寻址的任何原因?

c++ - 使用指针初始化结构数组 - C++ ...?

c++ - 内存寄存器的名称是如何分配的?

delphi - 是否可以在 Delphi 中将类型存储在变量中?