以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请从与下画线处号码对应的一组选项中选择正确的选项。
#include <stdio.h>
struct node
char data; struct node *next; ;
(48) CreatList(char *s)
struct node *h, *p, *q;
h=(struct node *)malloc(sizeof(struct node));
p=q=h;
while (*s!=’\0’ )
p=(struct node *)malloc(sizeof(struct node));
p->data= (49) ;
q->next=p;
q= (50) ;
s++;
p->next=’\0’;
return h ;
main()
char str[]="link list";
struet node *head ;
head=CreatList(str) ;
…
A.p->next
B.p
C.s
D.s->next
参考答案:B
解析: 因为该程序是要建立一个单向链表,我们在进行了一次值的插入之后,应该进入下一个值的插入,所以在此时,应该指向下一个要插入的地方。