誰能請解釋爲什麼在一個結構工程訪問一個聯盟內部嵌套結構元素的第一個方法和第二個不裏面?訪問變量的聯合的結構
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