yuAriellexi
yuAriellexi
2018-09-25 06:34

创建动态二维数组与二维数组初始化

5
  • 二维数组
  • c++
  • matrix
 #include <iostream>
using namespace std;

int main()
{

    int row, column;
    int sz;
    cout << "Enter the size of matrix, 2 * 2 or 3 * 3" << endl;
    scanf("%d%*c%d", &row, &column);
    sz = row * column;

    int **a = new int *[row];
    for (int i = 0; i < row; i++)
    {
        a[i] = new int[column]; 
    }
    //cout << "Please enter " << sz << " element of matrix:" << endl;
    a[3][3] = {{6, 1, 1}, {4, -2, 5}, {2, 8, 7}};

}

error: expected expression
a[3][3] = {{6, 1, 1}, {4, -2, 5}, {2, 8, 7}};
我想知道为什么这样做不对?我这样做的理由是a[3] = {1, 2, 3};
这样做是不是不是初始化,因为我已经动态分配了内存,已经创建了数组,所以a[3][3]= {{6, 1, 1}, {4, -2, 5}, {2, 8, 7}};是赋值多个值到一个数组元素a[3][3]

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换