栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > C++面试题库

下面关于“联合”的题目的输出是什么?

下面关于“联合”的题目的输出是什么?

a)
#i nclude <stdio.h>
union
{
int i;
char x[2];
}a;

void main()
{
a.x[0] = 10;
a.x[1] = 1;
printf(“%d”,a.i);
}
答案:266 (低位低地址,高位高地址,内存占用情况是Ox010A)
b)
     main()
     {
          union{                  
               int i;
               struct{            
                    char first;
                    char second;
               }half;
          }number;
          number.i=0x4241;        
          printf(“%c%cn”, number.half.first, mumber.half.second);
          number.half.first=’a’;  
          number.half.second=’b’;
          printf(“%xn”, number.i);
          getch();
     }
答案: AB   (0x41对应’A’,是低位;Ox42对应’B’,是高位)
       6261 (number.i和number.half共用一块地址空间)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/265864.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号