#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};這樣做是不是不是初始化,因為我已經動態(tài)分配了內存,已經創(chuàng)建了數組,所以a[3][3]= {{6, 1, 1}, {4, -2, 5}, {2, 8, 7}};是賦值多個值到一個數組元素a[3][3]
2 回答

largeQ
TA貢獻2039條經驗 獲得超8個贊
初始化是在你定義的時候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 關注
- 1339 瀏覽
添加回答
舉報
0/150
提交
取消