#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 expressiona[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 回答
largeQ
TA贡献2039条经验 获得超7个赞
初始化是在你定义的时候int a[3][3] = {{6, 1, 1}, {4, -2, 5}, {2, 8, 7}};
这样是没毛病的,而在定义之后a[3][3] = {{6, 1, 1}, {4, -2, 5}, {2, 8, 7}};这是赋值,a[3][3]这个楼上所说是第4行的第4列
- 2 回答
- 0 关注
- 1315 浏览
添加回答
举报
0/150
提交
取消