title: Head of a simple linked list changing
body: <p>Hello guys I am trying linked list implementation in C language </p>
  
  <p>I do by so In my linked_list.h file I have </p>
  
  <pre><code>struct Node{
      void *data;
      struct Node *next;
  };
  struct LinkedList{
      struct Node* head;
  };
  </code></pre>
  
  <p>And its implementation linked_list.c</p>
  
  <pre><code>struct LinkedList* Create_linked_list(){
      struct LinkedList* linked_list = (struct LinkedList*)malloc(sizeof(struct LinkedList));
      return linked_list;
  }
  
  struct Node* Get_last_node(struct LinkedList* linked_list){
      struct Node *temp = linked_list-&gt;head;
      while(temp-&gt;next != NULL){
          temp = temp-&gt;next; 
      }
  
      return temp;
  }
  
  struct Node* Get_node_at(struct LinkedList* linked_list,int position){
      if(position &gt;= get_size(linked_list)){
          return NULL;
      }else{
          struct Node *temp = linked_list-&gt;head;
          int i;
          for(i=0;i&lt; position;i++){
              temp = temp-&gt;next;
          }
          return temp;
      }
  }
  
  void Append_node(struct LinkedList* linked_list,void *data){
      struct Node *new_node = (struct Node*)malloc(sizeof(struct Node));
      new_node-&gt;data = data;
      new_node-&gt;next = NULL;
      if(linked_list-&gt;head == NULL){
          linked_list-&gt;head = new_node;
      }else{
          struct Node *last_node = Get_last_node(linked_list);
          last_node-&gt;next = new_node;
      }   
  }
  
  int get_size(struct LinkedList* linked_list){
      struct Node* temp = linked_list-&gt;head;
      int length;
      while(temp != NULL){
          length++;
          temp = temp-&gt;next;
      }
      return length;
  }
  
  
  void Delete_linked_list(struct LinkedList* linked_list){
      free(linked_list-&gt;head);
      free(linked_list);
  }
  </code></pre>
  
  <p>and in my main.c</p>
  
  <pre><code>int main(int argc,char *argv[]){
      struct LinkedList *linked_list = Create_linked_list();
  
      int i;
      for(i=1;i&lt;=10;i++){
          Append_node(linked_list,(void*)&amp;i);
      }
      struct Node *node_n = Get_node_at(linked_list,1);
      printf("%d\n",*(int*)node_n-&gt;data);
  
      Delete_linked_list(linked_list);
      return 0;
  }
  </code></pre>
  
  <p>I have two questions: </p>
  
  <p>1) I get the output as 11<br>
     It means that the head is changing in the recursion.<br>
     What is the reason for this?  </p>
  
  <p>2)Is it necessary to free the memory by </p>
  
  <pre><code>free(linked_list-&gt;head);
    free(linked_list);
  </code></pre>
  
  <p>or only <code>free(linked_list);</code> is sufficient?</p>