title: why am I getting segmentation fault? I am trying to solve the rat in a maze problem
body: <p>why am I getting segmentation fault? I am trying to solve the rat in a maze problem.
  Below is the code that is giving me the segmentation fault<br />
  May be there is some fault is passing 2D array to functions but seems alright to me
  I have applied the base conditions in function rinm and passing the solution matrix as well as the user input matrix from the main().</p>
  <pre><code>bool rinm(int** maze,int** sol,int n, int x, int y)
  {
      if(x==n-1 &amp;&amp; y==n-1)
      {
              sol[x][y]=1;
  
          //print the path
          for (int i = 0; i &lt; n; ++i)
          {
              /* code */
              for (int j = 0; j &lt; n; ++j)
              {
                  cout&lt;&lt;sol[i][j]&lt;&lt;&quot; &quot;;
  
              }
  
              cout&lt;&lt;endl;
          }
          return true;
      }
      else if(x&lt;0 || y&lt;0 || x&gt;=n || y&gt;=n || maze[x][y]==0)
      {
          return false;
      }
      
      sol[x][y]=1;
  
      bool up=rinm(maze,sol,n,x-1,y);
      bool down=rinm(maze,sol,n,x+1,y);
      bool right=rinm(maze,sol,n,x,y+1);
      bool left = rinm(maze,sol,n,x,y-1);
     
      sol[x][y]=0;
  
      if(up||down||right||left)
      {
          return true;
      }
  }
  </code></pre>
  <p>This is my main function.</p>
  <pre><code> int main()
      {
          int n;
          cin&gt;&gt;n;
          int** maze=new int*[n];//rows
          for (int i = 0; i &lt; n; ++i)
          {
              maze[i]=new int [n]; // columns
          }
          
          for (int i = 0; i &lt; n; ++i)
          {
              for(int j=0; j&lt;n;j++)
              {
                  cin&gt;&gt;maze[i][j];
              }
          }
      
          int** sol=new int*[n];
          for (int i = 0; i &lt; n; ++i)
          {
              sol[i]=new int [n]; // columns
          }
          for (int i = 0; i &lt; n; ++i)
          {
              for(int j=0; j&lt;n;j++)
              {
                  sol[i][j]=0;
              }
          }
          bool path=rinm(maze,sol,n,0,0);
          if(path==false)
              cout&lt;&lt;&quot;path doesnot exist\n&quot;;
      
          return 0;
      
      }
  </code></pre>
  <p>where am I going wrong?</p>