第一种,用点运算符进行内容的赋值和访问。
struct student
{
int score;
char name[128];
};
int main()
{
struct student stu;
strcpy(stu.name,"张三");
stu.score=99;
printf("%s %d\n",stu.name,stu.score);
第二种,当遇到结构体指针时,利用->来进行变量的赋值和访问,此时不能用点运算符!!!而且需要注意指针是否为野指针或NULL,为指针开辟一个空间来储存它本身。
struct student *p;
p=(struct student*)malloc(128);
p->score=100;
strcpy(p->name,"李四");
printf("%s %d\n",p->name,p->score);