我想try 为列表中的单元格创建一个allocate函数,但是当在其他函数中使用它时,我需要添加一个""号
我知道""在c中的意思(变量的地址),但我不明白为什么我需要在这里使用它?
这是我创建的分配函数
/*1*/void Allocate(struct cell **p) {
(*p) = malloc(sizeof(struct cell));
}
这就是我使用它的函数
void Makelist(struct cell **headP, int n){
struct cell *q;
struct cell *p;
int value;
Allocate(&p);///whyyyy????
*headP=p;
Ass_adr(p,NULL);
printf("\ngive the value on cell 1:");
scanf("%d",&value);
Ass_val(p,value);
for (int i=1; i<n;i++){
Allocate(&q);
Ass_adr(q,NULL);
Ass_adr(p,q);
printf("give the value in the cell %d:",i+1);
scanf("%d",&value);
Ass_val(p,value);
p=q;
}
}
我以为我只会打字
Allocate(p);
然而,如果我没有在主程序中添加"",它就会正常运行