The difference between the member operator (·) and the member operator pointing to the structure (->)

The difference between the member operator (·) and the member operator pointing to the structure (->)

Both are used to refer to the members of structure variables, but their application environments are completely different. The former is used in general structure variables, and the latter is used in conjunction with pointers to structure variables, for example: defined

struct student

{

long num;

float score;

};

struct student stud, *ptr=&stud;

Then stud.num, stud.score, ptr->num, etc. are all correct references, but ptr.num, stud->num are not allowed. In fact, ptr->num is equivalent to (*ptr).num, but In order to be more intuitive, this -> operator is specially provided.

Finally, it is pointed out that both of them have the highest priority and are combined in the direction from left to right.

Guess you like

Origin blog.csdn.net/weixin_44856544/article/details/114779913