title: Run-Time Check Failure #2 - Stack around the variable 's' was corrupted
body: <p>I have faced this problem : Run-Time Check Failure #2 - Stack around the variable 's' was corrupted in visual studio 12 . I also try this in codeblock but faced same problem . I run my code also in ideone.com it shows runtime error . Help me out ?
  my code is :</p>
  
  <p><code></p>
  
  <pre><code>#include&lt;iostream&gt;
    #include&lt;stdio.h&gt;
    #define MAX 50
    using namespace std;
    typedef struct
    {
      long var[20];
      long pos;
    }stack;
  
     void init_stack(stack *st)
     {
         long i;
         for(i=0; i&lt;MAX; i++)
          st-&gt;var[i] = -1;
         st-&gt;pos = 0;
       return ;
    }
  
    void push(stack *st, long item)
    {
      if(st-&gt;pos == MAX)
      {
          printf("stack overflow \n");
      }
      else
      st-&gt;var[st-&gt;pos+1] = item;
      st-&gt;pos++;
      return ;
    }
  
    void pop(stack *st)
    {
      //if(empty(st))
      if(st-&gt;pos == 0) 
          printf("stack underflow \n");
      else
      st-&gt;var[st-&gt;pos] = -1;
      st-&gt;pos--;
      return ;
    }
  
    long top(stack *st)
    {
      long temp;
      temp = st-&gt;var[st-&gt;pos];
  
      return temp;
      }
  
  bool empty(stack *st)
  {
      if(st-&gt;pos==0)
          return true;
      else
          return false;
  }
  
  int main()
  {
      stack s;
      long i, n=9, t;
      init_stack(&amp;s);
      printf("STACK PUSH\n");
      for(i=1; i&lt;=n; i++)
      {
          push(&amp;s, i);
          t = top(&amp;s);
          printf("  %ld\n", t);
      }
      printf("STACK POP\n");
      for(i=1; i&lt;=n; i++)
      {
          t = top(&amp;s);
          printf("  %ld\n", t);
          pop(&amp;s);
      }
      return 0;
  }
  </code></pre>
  
  <p></code></p>