简体   繁体   English

指针指向结构中的另一个指针

[英]Pointer points to another pointer in structure

I have structure named temp with member n :我有名为temp的结构,成员为n

struct temp
{
    int n;
}

I wish to declare a pointer p to access member n .我希望声明一个指针p来访问成员n

struct temp *p

How to access member n by another pointer p1 which points to pointer p .如何通过另一个指向指针p的指针p1访问成员n

You can access member n through a pointer to p with您可以通过指向p的指针访问成员n

temp a;
temp *p = &a;
temp **p1 = &p;
(*p1)->n = 2;

p1 is a pointer to p . p1是指向p的指针。 Dereferencing it gives a reference to p .取消引用它会引用p (*p1) and p are equivalent. (*p1)p是等价的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM