可能重复:
无法分配内存
我的以下代码运行良好:
double weight [600] [800][3];
double mean [600] [800][3];
double sd [600] [800][3];
double u_diff [600] [800][3];
for ( int i = 0; i < 600; i ++ )
{
for ( int j = 0; j < 800; j ++ )
{
for ( int k=0; k < 3; m ++ )
{
weight [i][j][k] = 0;
mean[i][j][k] = 0;
sd[i][j][k] = 6;
}
}
}
但是当我把它改成这种形式时:
int init = 6;
int C = 3;
for ( int i = 0; i < 600; i ++ )
{
for ( int j = 0; j < 800; j ++ )
{
for ( int k =0; k < 3; k ++ )
{
weight [i][j][k] = 1/C;
mean[i][j][k] = rand();
sd[i][j][k] = init;
}
}
}
它崩溃了。我什至尝试分别为“weight”、“mean”和“sd”工作。我怀疑它可能是数据类型,更改如下:
double value = rand();
weight[i][j][m] = value;
但错误仍然存在。这里有什么问题?