title: Remove value from front of queue in C
body: <p>I'm trying to use this function to remove a value from the front of a queue. It seems to work the first time (though I might be wrong about this) but when freeing a node the second time it triggers a breakpoint which crashes the program. How do I fix this?</p>
  
  <pre><code>printf("Value removed = %d\n", dequeue(myQueue));
  
  int dequeue(queue q)
  {
      if (q == NULL || q-&gt;head == NULL)
      {
          return 0;
      }
  
      node * head = q-&gt;head;
      node * temp = head;
  
      if (temp == NULL)
      {
          return;
      }
  
      int returnValue = head-&gt;value;
  
      //Free first node in queue
      head = temp-&gt;next;
      free(temp);
  
      //Return value that was removed
      return returnValue;
  }
  </code></pre>