首页 > 解决方案 > 获取指向指针的指针元素(c++)

问题描述

这是我写的代码:

#include <iostream>

using namespace std;
struct working{
    int*pointer;
    int inf;
};

int main()
{
  working one;
  working *two;
  working **three;
  one.inf=5;
  one.pointer=NULL;

  two=&one;
  cout<<two<<endl;
  cout<<two->pointer<<endl;
  cout<<two->inf<<endl;

  three=&two;
  cout<<three<<endl;
  cout<<three->pointer<<endl;

  return 0;
}

如何以与我所做的类似的方式获取inforpointer元素?如果可能的话,你能告诉我做什么。如果我用它切换它为什么不能编译?threetwo*three=twothree=&two

标签: c++pointers

解决方案


three = &two;
cout << (*three) << endl;
cout << (*three)->pointer << endl;

推荐阅读