谁能请解释为什么在一个结构工程访问一个联盟内部嵌套结构元素的第一个方法和第二个不里面?访问变量的联合的结构
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;
}
当你写一个问题,也有一些简洁和有用的格式化指令只是问题框右侧。请在下次阅读。 – 2010-07-17 11:18:03
这是什么意思“不起作用”?编译错误?运行时错误? – pmod 2010-07-17 11:35:21
如果仅在第二种方法中出现“分段错误”(在两种方法中都会出现这种情况),则不起作用。 – Nitzs 2010-07-17 11:42:35