使用可以吗?作为 GNU c 中结构的成员限定符而不是符号 ->。当符号 . 时,编译器不会提示。用于代替 ->.
最佳答案
.
用于访问结构体的成员; ->
用于访问指向的结构的成员。后者取消引用指针,然后获取成员。因此 p->x
相当于 (*p).x
。示例:
struct P {
int x;
int y;
};
struct P myP = {1,2};
struct P *p= &myP;
printf("%d, %d\n", myP.x, myP.y); // prints 1, 2
printf("%d, %d\n", p->x, p->y); // prints the same
printf("%d, %d\n", (*p).x, (*p).y); // is the same
关于我可以用吗 。作为 gnu c 结构中的成员限定符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54767268/