结构体指针
struct Student
{
int score;
char name[128];
};
int main()
{
struct Student stu1;
stu1.score = 100;
strcpy(stu1.name,"lao K");
printf("test\n");
printf("名字;%s,分数;%d\n",stu1.name,stu1.score);
struct Student *p;
//p.score = ; // 如果用结构体指针,就不能运算符访问结构体中的变量,要用->
p = (struct Student*)malloc(sizeof(struct Student));
p->score = 100;
strcpy(p->name,"zhang");
printf("名字;%s,分数;%d\n",p->name,p->score);
system("pause");
return 0;
}
运行结果;
//1.如果用结构体指针,就不能用点运算符访问结构体中的变量,要用->
//2.指针要注意是否是野指针或者NULL