繁体   English   中英

为什么我们使用点/箭头运算符来访问 c 中的结构变量

[英]why we are using dot/arrow operator to access structure variables in c

我不知道为什么我们使用它来访问变量。 有什么标准吗? 如果有它们是什么?

#include <stdio.h>
struct st {
  int i;
  char ch;
} s;
int main() {
  s.i = 10;
  printf("%d\n", s.i);
}

点运算符和箭头运算符不一样:

点运算符采用结构的属性。
箭头运算符采用结构的属性,您使用的指针是指。

These two lines are the same thing:
(*(*(*a).b).c).d

a->b->c->d

它看起来更实用,更好看,否则你必须使用顶部的那个看起来很难阅读,所以我们使用 -> 运算符,因为它更简单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM