Pointers on C——10 Structures and Unions.9

10.2.4 Accessing a Nested Structure


To access the member c, which is a structure, use the expression px->c. Its R‐value is the entire structure.

为了访问本身也是结构的成员。我们可以使用表达式px->c 它的左值是整个结构。


The dot operator can be added to this expression to access specific members of c. For example, the expression px->c.a has the following R‐value:

这个表达式可以使用点操作符访问c 的特定成员。例如,表达式px->c.a 具有下面的右值:


This expression contains both the dot and arrow operators. The arrow is used because px is not a structure, it points to a structure. Then the dot operator is used because px->c does not point to a structure, it is a structure.

这个表达式既包含了点操作符,也包含了箭头操作符之所以使用箭头操作符,是因为px 并不个结构,而是个指向结构的指针。接下来之所以要使用点操作符是因为px->c 的结果并不是个指针,而是个结构


Here is a more complex expression:

这里有个更为复杂的表达式:


*px->c.b


Examining this expression is easy if you take one step at a time. There are three operators, and the arrow goes first px->c gives the structure c. Adding .b to the expression selects the member b from structure c. b is an array, so px->c.b is a(constant) pointer to the first element of the array. Finally, the indirection is applied to this pointer, so the result is the first element of the array. The expression is diagrammed below.

如果你逐步对它进行分析,这个表达式还是比较容易弄懂它有个操作符,首先执行的是箭头操作符px->c 的结果是结构c 在表达式中增加.b 访问结构c 的成员b 。 b 个数组,所以px->b.c 的结果是一个(常量〉指针,它指向数组的第1 个元素最后对这个指针执行间接访问,所以表达式的最终结果是数组的第1 个元素这个表达式可以图解如下:


上一章 Pointers on C——10 Structures and Unions.8


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值