Accessing elements within a pointer of a struct inside another pointer to a struct
<p>Just trying to learn how nested pointers to structs work. How would I access an element within a pointer of a struct within another pointer to a struct? Thanks.</p>

<pre><code>#include &lt;iostream&gt;

typedef struct
{
  unsigned int            a;
  unsigned int            b;
  unsigned int            c;
} inner;

typedef struct
{
  unsigned int            d;
  unsigned int            e;
  inner * in;
} outer;

/* Function to use struct */
void test(outer * out)
{
  //Update the value of out-&gt;in-&gt;a.
  out-&gt;in-&gt;a = 5;
}

int main() {
  outer * out;
  test(out);

  std::cout &lt;&lt; "My updated value: " &lt;&lt; out-&gt;in-&gt;a &lt;&lt; std::endl;
}
</code></pre>

<p>I get a "Segmentation fault (core dumped)".</p>

<p>Edit: Made changes based on suggestions.</p>

<pre><code>#include &lt;iostream&gt;

typedef struct
{
    unsigned int            a;
    unsigned int            b;
    unsigned int            c;
} inner;

typedef struct
{
    unsigned int            d;
    unsigned int            e;
    inner * in = new inner();
} outer;

/* Function to use struct */
void test(outer * out)
{
    //Update the value of out-&gt;d.
    out-&gt;d = 3; 
    //Update the value of out-&gt;in-&gt;a.
    out-&gt;in-&gt;a = 5;
}

int main() {

    outer out; 
    outer* p = &amp;out; 

    test(p);

    std::cout &lt;&lt; "My updated value for d: " &lt;&lt; p-&gt;d &lt;&lt; std::endl;
    std::cout &lt;&lt; "My updated value for a: " &lt;&lt; p-&gt;in-&gt;a &lt;&lt; std::endl;
}
</code></pre>

<p>I now get the correct values updated. However I have a warning now </p>

<p>"warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11"</p>

<pre><code>inner * in = new inner();
</code></pre>

<p>How do I fix this warning?</p>