指向指针的指针问题;求帮忙解释一下
int **p;p=(int**)malloc(10*sizeof(int*));
for(i=0;i<10;i++)
p[i]=(int*)malloc(20*sizeof(int));
这样写错在哪里,我简单跟踪一下,发现 p 分配的有地址,p[0] 也有地址,但从1之后就错了为什么,求解释?
Group_inform group; Graph g1,*g; int i,j; g=&g1; group.group_family=(int**)malloc(group_num*sizeof(int*)); group.fitness=(double*)malloc(group_num*sizeof(double)); group.probability=(double*)malloc(group_num*sizeof(double)); for(i=0;i<group_num;i++) group.group_family[i]=(int*)malloc(g->vertex_num*sizeof(int));
#ifndef __hereditary_h #define __hereditary_h #define Generation_Num 50 //种群迭代次数 #define group_num 20 //种群成员数目 #define mating_probability 0.8 //交配概率 #define mutation_probability 0.001 //变异概率 typedef struct Group_inform { int **group_family; double *fitness; double *probability; }Group_inform;