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;
}
}

猜你喜欢

转载自www.cnblogs.com/zjhangia/p/12384333.html