简体   繁体   English

如何访问对结构的引用的引用的成员。 (结构**)

[英]How to access memebers of a reference to a reference to a struct. (struct**)

I'm very new to C programming.我对 C 编程很陌生。 And I'm asking myself how I can access mebers of double referenced structs.我在问自己如何访问双引用结构的成员。 (Not sure if you even would name it like this.) (不确定你是否会这样命名。)

So having this simple example:所以有这个简单的例子:

#include  <stdio.h>
#include  <string.h>

typedef struct {
    char n[4];
} inner;
typedef struct {
    inner inner[5];
} outer;


int main(void)
{
    outer o;
    strcpy(o.inner[0].n, "123");
    strcpy(o.inner[1].n, "ABC");
    
    // Working. Prints "123".
    printf("%s\n", o.inner[0].n);
    
    outer* oo = &o;
    
    // Working. Prints "123".
    printf("%s\n", oo->inner[0].n);
    
    outer** ooo = &oo;
    
    // Not working. Need help here, please.
    printf("%s\n", *ooo->inner[0].n);
    
    return 0;
}

How can I access members of outer** ooo .我如何访问outer** ooo成员。 I tried something in the last printf statement, but is not working.我在最后一个 printf 语句中尝试了一些东西,但没有用。

Thanks to @Ted Lyngmo and @Ian Abbott.感谢@Ted Lyngmo 和@Ian Abbott。 The correct answers are:正确答案是:

(*ooo)->inner[0].n

or要么

ooo[0]->inner[0].n

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

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