c pointer

#define <stdio.h>
#define <stdlib.h>
#define STU_SIZE sizeof(stu)
typedef struct student{
int id;
struct student* next;
}stu;
void p_list(stu *node);
int main(int argc, char** argv) {

stu* head;
stu* temp;
head = NULL;
for(int i = 0; i < 20; i ++){
temp = malloc(STU_SIZE);
temp->id = i;
i += 2;
temp->next = head;
head = temp;
}
p_list(head);
return 0;
}

void p_list(stu* node){
while(node != NULL){
printf("id:%d\thead:%d\thead->next:%d\n", node->id, node, node->next);
node = node->next;
}
}
posted @ 2020-02-29 17:48  zjhangia  阅读(165)  评论(0编辑  收藏  举报