title: Double pointers in stack implementation of linked list
body: <p>I was reading a book recently and this is the explanation for implementing stack in Linked list. Here follows the explanation:</p>
  
  <pre><code>typedef struct Element { 
      struct Element *next; 
      void *data;
  } Element;
  </code></pre>
  
  <p>The corresponding prototypes for push and pop follow:</p>
  
  <pre><code>void push( Element *stack, void *data );
  void *pop( Element *stack );
  </code></pre>
  
  <p>Now consider what happens in these routines in terms of proper functionality and error handling. 
  Both operations change the first element of the list. The calling routine’s stack pointer must be modified to reflect this change, but any change you make to the pointer that is passed to these functions won’t be propagated back to the calling routine. You can solve this problem by having both routines take a pointer to a pointer to the stack. This way, you can change the calling routine’s pointer so that it continues to point at the first element of the list. Implementing this change results in the following:</p>
  
  <pre><code>void push( Element **stack, void *data );
  void *pop( Element **stack );
  </code></pre>
  
  <p>However, what I wonder is, what is the need to put double pointers for the stack? I understand the concept of double pointers, but however, when a new node is created using 
  <code>Element *node1 = (Element *) malloc (sizeof(Element));</code>, we already have the pointer to the node. Why not just send this pointer itself instead of using double pointer?</p>