title: C Passing a list from struct to another function
body: <p>Can anybody explain me what is happening?
  This code works ok:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct def_List List;
  
  struct def_List {
      int x;
      int y;
      List *next;
  };
  
  typedef struct def_Figures {
      List *one;
      List *two;
  } Figures;
  
  void another_function(List *l) {
      l = (List*) malloc(sizeof(List));
      l-&gt;x = 1;
      l-&gt;next = NULL;
  }
  
  void function(Figures *figures) {
      another_function(figures-&gt;one);
  }
  
  int main() {
      Figures ms;
      function(&amp;ms);
      printf("%d",ms.one-&gt;x);
      return 0;
  }
  </code></pre>
  
  <p>Prints "1".
  I add third list:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct def_List List;
  
  struct def_List {
      int x;
      int y;
      List *next;
  };
  
  typedef struct def_Figures {
      List *one;
      List *two;
      List *three;
  } Figures;
  
  void another_function(List *l) {
      l = (List*) malloc(sizeof(List));
      l-&gt;x = 1;
      l-&gt;next = NULL;
  }
  
  void function(Figures *figures) {
      another_function(figures-&gt;one);
  }
  
  int main() {
      Figures ms;
      function(&amp;ms);
      printf("%d",ms.one-&gt;x); // 1
      return 0;
  }
  </code></pre>
  
  <p>Prints "-1992206527".</p>
  
  <p>It works well with one or two lists, but when I add third or more, something is going wrong. Why?</p>