title: Stack structure pointing to itself - What's going on here?
body: <pre><code>typedef struct _s {     // same definition as before   
      int         value;
      struct _s   *next;
  }  STACKITEM;
  
  STACKITEM    *stack = NULL;
  
   ....
  
  void push_item(int newvalue)
  {
      STACKITEM  *new = malloc( sizeof(STACKITEM) );  
  
      if(new == NULL) {     // check for insufficient memory   
          perror("push_item");
          exit(EXIT_FAILURE);
      }
  
      new-&gt;value   = newvalue;
      new-&gt;next    = stack;
      stack        = new;
  }
  </code></pre>
  
  <p>What is the purpose of the two lines:</p>
  
  <pre><code>new-&gt;next    = stack;
  stack        = new;
  </code></pre>
  
  <p>From what I can see, the next field of the new STACKITEM structure is set to point to stack. Stack is then set to point to the STACKITEM structure new? Is this correct?</p>
  
  <p>If so, I do not understand what the point of this is. It seems like it is 'wrapping' the stack around and 'closing' it. In other words, when we attempt to access the next structure in the stack, since this is actually the last structure available, it can only access itself?</p>
  
  <p>Thank you.</p>