指针指向堆区空间
#include <stdio.h>
#include <stdlib.h>
struct Student
{
int age;
char name[50];
int score;
};
int main(int argc, char const *argv[])
{
//定义一个结构体类型指针
struct Student *p;
//指针指向堆区空间
p = (struct Student *)malloc(sizeof(struct Student));
if(p == NULL)
{
printf("malloc err\n");
return -1;
}
p->age = 18;
strcpy(p->name, "mike");
p->score = 59;
printf("%d, %s, %d\n", p->age, p->name, p->score);
if(p != NULL)
{
free(p);
p = NULL;
}
return 0;
}