title: Why the following implementation overrides the elements/ or prints only one element
body: <p>I am trying to implement linked list in c. In the insertion of the element, if the head is not NULL, I am trying to add a node in the beginning of the linked list
  Here is my code</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  struct Node{
      int data;
      struct Node* next;
  };
  
  struct Node* head ;
  
   void insert(int data){
  
       struct Node* temp = (struct Node*) malloc(sizeof(struct Node));
  
      temp-&gt;data = data;
      if(head!=NULL){
          temp = head;
          head = temp;
       }
  
      temp -&gt; next = NULL;
      head = temp;
  
   }
  
  
  void print(){
  
      struct Node* temp = head;
      while(temp!=NULL){
          printf("%d \n",temp-&gt;data);
          temp = temp-&gt;next;
      }
  }
  
  
  int main(){
    head = NULL;
    insert(2);
    insert(3);
    insert(5);
    print();
  
      return 0;
  }
  </code></pre>
  
  <p><br>
  But on print function, I am getting only 2 as output. What might be the reason?</p>