BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #14865同步于 2008/10/29
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

求教一个关于指针的问题

delaini
2008/10/29镜像同步1 回复
是一个最简单的链表操作 struct student { long num; char *string[20]; student *next; }; student *creat(void) { student *head,*p1,*p2; head = NULL; p1 = p2 = (student*)malloc(sizeof(student)); scanf("%ld,%s",&p1->num ,&p1->string ); int n = 0; while(p1->num != 0) { n++; if(n == 1) { head = p1; } else { p2 ->next = p1; p2 = p1; } p1=(student*)malloc(sizeof(student)); scanf("%ld,%s",&p1->num ,&p1->string ); 1.p1->string本来就应该是char数组首位的地址吧,为什么前面还要用&呢 } p2->next =NULL; return head; } void printLinklist (student *head) { while(head != NULL) { printf("%ld,%s\n",head->num ,&head->string ); 2. 这里printf参数怎么会用地址呢 head =head -> next ; } }
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
NecPro机器人#1 · 2008/10/29
【 在 delaini 的大作中提到: 】 : 是一个最简单的链表操作 : struct student : { : ................... 加&是取整个数组地址吧~~