title: Struct Pointer in C initialised only the first pointer with NULL and 0
body: <p>I have a struct for a Double List with next and prev pointers. I'm trying to create a second list where I'm putting the fruits with odd number of calories from the first list. But I don't know why, when the second list enters in the append function, after I set the first and last pointers to NULL, only the first pointer is still set on NULL, the last pointer being uninitialised.</p>
  <pre><code>#define _CRT_SECURE_NO_WARNINGS
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #include&lt;malloc.h&gt;
  
  typedef struct Node Node;
  typedef struct DoubleList DoubleList;
  typedef struct Fruit Fruit;
  
  struct Fruit {
      char* name;
      int calories;
  };
  
  struct Node {
      Fruit info;
      Node* next, * prev;
  };
  
  struct DoubleList {
      Node* first;
      Node* last;
  };
  
  void append(DoubleList* list, Fruit f) {
      Node* new = (Node*)malloc(sizeof(Node));
      new-&gt;info = f;
      new-&gt;next = NULL;
      new-&gt;prev = NULL;
  
      if (list-&gt;last) {
          list-&gt;last-&gt;next = new;
          list-&gt;last = new;
      }
      else {
          list-&gt;last = list-&gt;first = new;
      }
  }
  
  void main() {
      DoubleList ld;
  
      ld.first = NULL;
      ld.last = NULL;
  
      append(&amp;ld, createFruit(&quot;Avocado&quot;, 201));
      append(&amp;ld, createFruit(&quot;Apple&quot;, 251));
      append(&amp;ld, createFruit(&quot;Strawberries&quot;, 100));
      append(&amp;ld, createFruit(&quot;Cherry&quot;, 50));
  
      DoubleList* ld2 = (DoubleList*)malloc(sizeof(DoubleList));
      //DoubleList ld2;
      ld2-&gt;first = NULL;
      ld2-&gt;last = NULL;
      Node* temp = ld.first;
  
      while (temp)
      {
          Node* aux = temp-&gt;next;
          if (temp-&gt;info.calories % 2 == 1) {
              append(&amp;ld2, temp-&gt;info); 
              //but I don't know why this line won't send the list to the append function with the pointers set on NULL
              //append(ld2, temp-&gt;info); this line is working
  
          }
          else {
              free(temp-&gt;info.name);
              free(temp);
          }
          temp = aux;
      }
      show(*ld2);
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/mb6KY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mb6KY.jpg" alt="Before entering in the append function" /></a></p>
  <p><a href="https://i.stack.imgur.com/wdX04.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wdX04.jpg" alt="After entering in the append function" /></a></p>