C语言中访问结构体成员时用‘.’和‘->’的区别

举个例子,定义了一个叫Student,别名为stu的结构类型,我们声明了一个结构体变量叫stu1,声明了一个结构体指针为stuP。

typedef struct Student
{
    char name[N];
    int id;
    int score;
    struct Student *next;
} stu;
stu stu1;
stu* stuP;

 那么我们访问他们的结构体成员时要这样

stu1.name="Xiao Ming";
stu1.id=2015211;

stuP->name="Xiao Hua";
stuP->id=2015311;

也就是说,结构体变量的成员用‘.’,结构体指针的成员用‘->’。

原文地址:https://www.cnblogs.com/flipped/p/5293636.html