代码中p是干什么的?p->num = num;中->什么意思?p->next = NULL;这个呢?

img

img


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct stud_node {
int num;
char name[20];
int score;
struct stud_node *next;
};
struct stud_node *head, *tail;

void input();

int main()
{
struct stud_node *p;

head = tail = NULL;
input();
for ( p = head; p != NULL; p = p->next )
    printf("%d %s %d\n", p->num, p->name, p->score);

return 0;

}

/* 你的代码将被嵌在这里 */

img


void input()
{
int num;
scanf("%d", &num);
while(num)
{
struct stud_node* p = NULL;
p = (struct stud_node*)malloc(sizeof(struct stud_node));
p->num = num;
scanf("%s %d", &p->name, &p->score);
p->next = NULL;
if(head){
tail->next = p;
tail = p;
}else{
head = p;
tail = p;
}
scanf("%d", &num);
}
}

调用指针指向的数据,定义指针结构体用->访问,非指针用 .