What is wrong with passing this argument?

I’ve been working on a problem in which I need to pass a multidimensional array to a function, specifically 2D array. In C++ although, I’m using the correct syntax, the compiler complains errors that says,

enter image description here

My code:

void traverseArraySpirally(int rows, int columns, int array[][columns])
{
    int top_row{}, bottom_row{rows-1};
    int left_column{}, right_column{columns-1};

    int i{};

    while(top_row <= bottom_row && left_column <= right_column)
    {
        i = left_column;
        while(i <= right_column)
        {
            cout << array[top_row][i] << " ";
            i++;
        }
     // more code here
     ....
     ....
     ....
     ....
     ....
    }
}

Main function:

int main()
{
    int rows{}, columns{};
    cout << "Enter the dimensions of 2D array (n & m): ";
    cin >> rows >> columns;

    int array[rows][columns];

    input(rows, columns, array);

    traverseArraySpirally(rows, columns, array);
    
    return 0;
}

Can’t figure out what the problem is, please help.

Source: Windows Questions C++

LEAVE A COMMENT