我正在尝试执行一段非常简单的代码。 但是我无法找到T [i] [j]的值是如何突然改变的。
void initialize(float** &T,int NP,int D,int low,int high)
{
int i = 0,j = 0;
T = (float **)malloc(NP*sizeof(float));
for(i = 0;i<NP;i++)
{
T[i] = (float *)malloc(D*sizeof(float));
for(j = 0;j<D;j++)
{
T[i][j] = low + (high - low)*((float)rand()/(float)RAND_MAX);
if(i==0)
{
printf("%p :\t",&T[i][j]);
printf("%f\n",T[i][j]);
}
}
}
printf("\n");
for(j = 0;j<D;j++)
{
printf("%p :\t",&T[0][j]);
printf("%f\n",T[0][j]);
}
printf("\n");
}
float** T = NULL;
initialize(T,NP,D,low,high);
0x1fc5070:3.401877 0x1fc5074:-1.056171 0x1fc5078:2.830992 0x1fc507c:2.984400 0x1fc5080:4.116474 0x1fc5084:-3.024486 0x1fc5088:-1.647773 0x1fc508c:2.682296 0x1fc5090:-2.222253 0x1fc5094:0.539700
0x1fc5070:0.000000 0x1fc5074:0.000000 0x1fc5078:0.000000 0x1fc507c:0.000000 0x1fc5080:0.000000 0x1fc5084:0.000000 0x1fc5088:0.000000 0x1fc508c:0.000000 0x1fc5090:0.000000 0x1fc5094:0.000000
答案 0 :(得分:0)
变化:
T = (float **)malloc(NP*sizeof(float));
为:
T = (float **)malloc(NP*sizeof(float *));