c - 在 C 中取消引用结构变量

标签 c structure operator-precedence

我有两个这样的结构

typedef struct foo_ {
int id;
int var1;
int var2; 
} foo_t;

typedef struct bar_ {
int member1;
int member2;
foo_t an_array[10]; 
} bar_t;

我有一个指向结构 bar_ 的指针作为 bar_t *ptr

现在我需要访问 foo 中的 id

我得到它作为 ptr->an_array[index].id 因为它是一个整数,所以不会有任何问题。 但是如何通过引用传递变量 id

&ptr->an_array[index].id 似乎不起作用 &ptr->(an_array[index].id)

也不行

我已经完成了优先级,但仍然无法正常工作。

谁能帮我解决这个问题

最佳答案

再次检查您的代码 - &ptr->an_array[index].id 应该可以正常工作。后缀运算符(->[].)绑定(bind)比&更紧密,所以应该没有问题.也许您的原始代码中还有其他问题?

关于c - 在 C 中取消引用结构变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29118169/

相关文章:

C警告: initialization makes pointer from integer without a cast [enabled by default]

clojure - 如何在 clojure 中的 HashMap 上插入 if

r - 在 R 中,如何确定用户定义的中缀运算符的运算符优先级?

Python:和/或运算符奇怪的行为

Perl 三元条件运算符

C 地址偏移量

c - C 语言中的指针和数组。概念不太明确。

c# - 自动提交表单后搜索浏览器内容

我可以在 C 结构中定义函数吗?

git - 在 Git 中管理多项目分支