Why run error is occurring

Why is my code showing run error for anti-clockwise spiral print of 2D Array.

#include
using namespace std;

void Spiral_Print(int **A,int m,int n)
{
int startRow=0;
int startCol=0;
int endRow=m-1;
int endCol=n-1;

while(startRow<=endRow && startCol<=endCol)
{
    int i;

    for(i=startCol;i<=endCol;i++)
    {
        cout<<A[i][startRow]<<","<<" ";
    }
        
    startRow++;

    for(i=startRow;i<=endRow;i++)
    {
        cout<<A[endCol][i]<<","<<" ";
    }

    endCol--;

    if(endRow>startRow)
    {
        for(i=endCol;i>=startCol;i--)
        {
            cout<<A[i][endRow]<<","<<" ";
        }
    endRow--;
    }

    if(endCol>startCol)
    {
        for(i=endRow;i>=startRow;i--)
        {
            cout<<A[startCol][i]<<","<<" ";
        }
    startCol++;  
    } 
}
cout<<"END";

}

int main()
{
int m,n,i,j;
cin>>m>>n;

int **A=new int*[m];
for(i=0;i<m;i++)
{
    A[i]=new int[n];
}
for(i=0;i<m;i++)
{
    for(j=0;j<n;j++)
    {
        cin>>A[i][j];
    }
}
Spiral_Print(A,m,n);

}

hi @Mukul-Shane-1247687648773500
I have corrected ur code -->


It’s working fine and passing all test cases now…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.