title: Recursive Tower of Hanoi,Access violation/segmentation fault, on dev c++ compiler
body: <p>//The following code generates access violation or segmentation fault
  //i am looking for simple solution to tower of hanoi, which i should write myself
  //please indicate flaws in below code rather than giving your elite codes :)</p>
  
  <p>//Recursive solution to Towers of Hanoi problem using three stacks</p>
  
  <pre><code>  #include &lt;iostream&gt;
    using namespace std;
  
    #define max 50
  
   typedef struct stack{ //union?
          int tos;
          int els[max]; //stack-&gt;els[1] = tos
  }stack; //template stack?
  
  
  void toh(int, stack * , stack *, stack *);
  void display(stack * );
  
  int main(){
      cout&lt;&lt;"Enter the number of discs ( &lt;=50 ) in Tower of Hanoi\n";
      int n;
      cin&gt;&gt;n;
      stack *A,*B,*C;
      toh(n, A,B,C);
      system("pause");
      return 0;
  }
  void toh( int n, stack *A, stack *B, stack *C){
      if ( n == 1 ) {
           int temp = A-&gt;els[A-&gt;tos]; //switch case i=1,2,3 tos[i]
           A-&gt;tos -= 1; //OR stack * A, A-&gt;tos?
           C-&gt;tos += 1;
           C-&gt;els[C-&gt;tos] = temp;  
                 //     push the popped item in stack C
           cout&lt;&lt;"A\t";
           display(A);
           cout&lt;&lt;"\nB\t";
           display(B);
           cout&lt;&lt;"\nC\t";
           display(C);
      }
      else {
           toh( n-1, A, C, B);
           toh( 1, A, B, C);
           toh( n-1, B, A, C);
      }
  }
  void display(stack * X){ //and not int[] stack
       cout&lt;&lt;"The stack elements are :\n";
            for( int i = 1; i &lt;= X-&gt;tos; i++){//impo to start with 1 if tos = 0 init
                 cout&lt;&lt;X-&gt;els[i];
                 cout&lt;&lt;"\t";
            }
  }
  </code></pre>