为二维数组中的变量赋值时出现分段错误[关闭]

问题描述 投票:0回答:0
#include <iostream>
using namespace std;

int main()
{

    int column = 2, row = 3;

    int **array = new int *[row];
    for (int i = 0; i < column; i++)
    {
        array[i] = new int[column];
    }

    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < column; j++)
        {
            array[i][j] = -1;//making every entry -1
        }
    }

    cout << "SUCCESS" << endl;

    return 0;
}

当我运行上面的代码时出现分段错误。有人可以向我解释为什么当我运行上面的代码时出现分段错误吗?

c++ arrays multidimensional-array segmentation-fault dynamic-memory-allocation
© www.soinside.com 2019 - 2024. All rights reserved.