[英]why we are using dot/arrow operator to access structure variables in c
I dont kno why we are using this to access variables.我不知道为什么我们使用它来访问变量。 Is there any standards?有什么标准吗? if there what are they?如果有它们是什么?
#include <stdio.h>
struct st {
int i;
char ch;
} s;
int main() {
s.i = 10;
printf("%d\n", s.i);
}
The dot operator and the arrow operator are not the same:点运算符和箭头运算符不一样:
The dot operator takes the attribute of a structure.点运算符采用结构的属性。
The arrow operator takes the attribute of the structure, the pointer you are using refers to.箭头运算符采用结构的属性,您使用的指针是指。
These two lines are the same thing:
(*(*(*a).b).c).d
a->b->c->d
It just seems more practical and better to look at, otherwise you'd have to use the one at the top which seems very hard to read, so we use the -> operator because it's much simpler.它看起来更实用,更好看,否则你必须使用顶部的那个看起来很难阅读,所以我们使用 -> 运算符,因为它更简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.