title: Crash in C program while retrieving an item from a stack
body: <p>The following code crashes on the second <code>Pop()</code> call. I'm a novice with C and I've been staring at this code now for over an hour and i can't see the error. Any ideas to help me out on why this code is crashing?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #define StackDataSize 100
  
  typedef struct Stack
  {
      int index;
      void *data[StackDataSize];
  } Stack;
  
  void* Pop(Stack *s)
  {
      if(s-&gt;index &gt;= 0)
      {
          return s-&gt;data[s-&gt;index--];
      }
      else
      {
          fprintf(stderr, "ERROR: Stack Empty\n");
          return NULL;
      }
  }
  
  void Push(Stack *s, void *v)
  {
      if(s-&gt;index &lt; StackDataSize)
      {
          s-&gt;data[++s-&gt;index] = v;
      }
      else
      {
          fprintf(stderr, "ERROR: Stack Full\n");
      }
  }
  
  int main(void)
  {
      Stack s = {-1}, *intstack = &amp;s;
  
      int x = 123456;
      Push(intstack, &amp;x);
  
      printf("%d\n", *(int*)Pop(intstack));
      printf("%d\n", *(int*)Pop(intstack));
  
      return 0;
  }
  </code></pre>