【发布时间】:2019-08-22 01:11:33
【问题描述】:
我正在尝试创建一个具有函数的动态矩阵,但首先我决定对分配进行分段,以便我知道一切正常。但是创建不起作用。
我尝试移动括号,使用不同的值,但它总是在 i=2 时崩溃
int rows=4;
int columns=4;
int cont=1;
int ** Mat;
Mat=(int**)malloc(rows*columns*sizeof(int));
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
printf("%d",i);
*(*(Mat+i)+j)=cont++;
}
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
printf("%2d ", *(*(Mat+i)+j) ); /* a[i][j] */
}
printf("\n");
}
我没有收到任何编译错误,我希望这样 1234 5678 9101112 13141516
【问题讨论】:
标签: c