博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++union
阅读量:4154 次
发布时间:2019-05-25

本文共 452 字,大约阅读时间需要 1 分钟。

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%c/n", number.half.first, mumber.half.second);
          number.half.first='a';  
          number.half.second='b';
          printf("%x/n", number.i);
          getch();
     }
答案: AB   (0x41对应'A',是低位;Ox42对应'B',是高位)

       6261 (number.i和number.half共用一块地址空间)

转载地址:http://aieti.baihongyu.com/

你可能感兴趣的文章
人机交互实验:Android开发之人物移动、地图滑动、传感器、触屏的应用
查看>>
在人机交互实验中遇到的一些问题
查看>>
可视化实验2——用D3做图表
查看>>
Github-git pull解决远程与本地仓库的冲突
查看>>
python调用matlab环境配置,非常详细!!!
查看>>
Python-格式化输入、字符串分割
查看>>
JavaScript图片旋转缩放、像素矩阵获取
查看>>
rgb和Lab,rgb和hsl的色彩空间转换
查看>>
两步解决python调用Matlab的脚本和函数文件
查看>>
pytorch之nn.Conv1d详解
查看>>
UnsatisfiableError: The following specifications were found to be in conflict
查看>>
技术文档整理
查看>>
scala Md5加密实现
查看>>
js实现全选单选的添加并添加和删除选择的元素
查看>>
微信小程序 手机号-验证码登录接口
查看>>
Access restriction: The method 'CharacterDecoder.decodeBuffer(String)' is not API
查看>>
MySQL锁等待问题(ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction)
查看>>
Eclipse设置Working Set管理项目和detach合并分离窗口
查看>>
java中大整型BigInteger及setBit和testBit方法
查看>>
网站优化之使用Free marker静态化网站文章页
查看>>