title: Setting struct variables - C
body: <p>I have some code in the following kind of layout, I believe that the <code>topExample</code>/<code>botExample</code> aren't being set properly when I call <code>addTopBotExample</code>. I think this is due to the top bot variables being on the functions stack and so being cleared when the function ends? I have a feeling that perhaps I need to <code>malloc</code> the memory first, but am not sure how I would go about doing this are even if its the right approach. </p>
  
  <pre><code>typedef struct Example Example;
  struct Example {
     /* normal variables ...*/
     Example *topExample;
     Example *botExample;
  };
  
  ....
  
  void addTopBotExample(Example **example, int someVariable) {
      Example top = createTopExample(int someVariable); //(createTopExample returns a
                                                        //type Example based on some input)
      Example bot = createBotExample(int someVariable);
      (*example)-&gt;topExample = &amp;top;
      (*example)-&gt;botExample = &amp;bot;
      return;
  }
  </code></pre>