c – 工会概念的混乱
发布时间:2020-12-16 10:22:33 所属栏目:百科 来源:网络整理
导读:#includestdio.hunion node { int i; char c[2];};main() { union node n; n.c[0] = 0; n.c[1] = 2; printf("%dn",n.i); return 0;} 我认为它给出512输出因为第一个字节中的c [0]值存储而第二个字节中存储了c [1]值,但是给出了1965097472.为什么? 我在wind
#include<stdio.h> union node { int i; char c[2]; }; main() { union node n; n.c[0] = 0; n.c[1] = 2; printf("%dn",n.i); return 0; } 我认为它给出512输出因为第一个字节中的c [0]值存储而第二个字节中存储了c [1]值,但是给出了1965097472.为什么? 解决方法
你的联盟分配了四个字节,从以下开始:
[????] [????] [????] [????] 您设置至少两个重要字节: [????] [????] [0x02] [0x00] 然后,您将所有四个字节打印为整数.你不一定会得到512,因为任何东西都可以在那些最重要的两个字节中.在这种情况下,你有: [0x75] [0x21] [0x02] [0x00] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |