Pointers on C——10 Structures and Unions.6

10.2 Structures, Pointers, and Members


The operators for accessing structures and their members directly and through pointers are quite simple, but they can become confusing when applied in complicated situations. Here are some examples to help you better understand how the operators work. The examples use the following declarations.

直接或通过指针访问结构和它们的成员的操作符是相当简单的,但是当它们应用于复杂的情形时就有可能引起混淆这里有几个例子,能帮助你更好地理解这两个操作符的工作过程这些例子使用了下面的


typedef struct {

int a;

short b[2];

} Ex2;


typedef struct EX {

int a;

char b[3];

Ex2 c;

struct EX *d;

} Ex;


Structures of type Ex will be pictured like this:

类型为EX 的结构可以用下面的图表示:


The structures are pictured this way to make the examples clearer. In fact, the diagram is not completely accurate, because the compiler avoids wasting space between the members whenever it can.

我用图的形式来表示结构,使这些例子看上去更清楚一些。事实上,这张图并不完全准确,因为编译器只要有可能就会设法避免成员之间的浪费空间。


The first examples will use these declarations:

第1 个例子将使用这些声明:


Ex x = { 10, "Hi", {5, { -1, 25 } }, 0 };

Ex *px = &x;


which produce the following variables:

它将产生下面这些变量:


We will now examine and diagram different expressions using the notation from Chapter 6.

我们现在将使用第6 章的记法研究和图解各个不同的表达式

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值