title: How to delete the first node of a linked list in c++
body: <p>I have been trying to delete the first node from a single linked list. What I did is as follow</p>
  
  <ul>
  <li>create a temporary node pointing to the head node</li>
  <li>move the head to the next node</li>
  <li>free the temporary node and return the head</li>
  </ul>
  
  <p>After generating a simple linked list as : <code>1 - &gt; 2 -&gt; 3 -&gt; 4 -&gt; 5</code> </p>
  
  <p>and calling my method for deleting the first node the result is as not correct. It returns the following linked list: <code>0 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5</code></p>
  
  <p>I didn't get why does the <code>0</code> still exists.</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  struct Node
  {
      int data;
      struct Node *next;
  };
  
  Node* Delete(Node *head)
  {
      Node* temp = head;
      head = head-&gt;next;
      delete temp;
      return head;
  }
  
  int main(void) {
  
      Node* head = new Node();
      Node*  temp = head;
  
      for(int i=1; i&lt;=5; i++)
      {
          Node* newNode = new Node();
          newNode-&gt;data = i;
          newNode-&gt;next = NULL;
  
          temp-&gt;next = newNode;
          temp = newNode;
      }
  
      Delete( head = head-&gt;next );
  
      while(head != NULL)
      {
          cout&lt;&lt;head-&gt;data&lt;&lt;" ";
          head = head-&gt;next;
      }
      cout&lt;&lt;endl;     
  
     return 0;
  }
  </code></pre>