【发布时间】:2010-07-17 11:15:52
【问题描述】:
谁能解释一下为什么第一种访问结构中的联合内的嵌套结构元素的方法有效而第二种无效?
typedef struct element Node;
struct element
{
int type;
union
{
int value;
Node *child[2];
} u;
};
int main()
{
Node n;
Node *p;
n.type = 0;
p = n.u.child[0];
p->type = 10; // 1st method
(n.u.child[1])->type = 24; // 2nd method
return 0;
}
【问题讨论】:
-
当你写一个问题时,问题框右侧有一些简洁且有用的格式说明。请下次阅读。
-
“不起作用”是什么意思?编译错误?运行时错误?
-