40.结构体套一级指针
#include
#include
struct Student{
int age;
char *name;
int score;
};
int main()
{
struct student *p;
//需要给p分配内存
p = (struct Student *)malloc(sizeof(struct Student));
p->name = (char *)malloc(strlen("mike") + 1);
if(p == NULL){
printf("分配失败\n");
return 0;
}
p->age = 18;
strcpy(p->name, "mike");
p->score = 59;
printf("%d, %s, %d\n", p->age, p->name, p->score);
if(p->name != NULL){
free(p->name);
p->name = NuLL;
}
if(p != NULL){
free(p);
p = NULL;
}
return 0;
}