当前位置:网站首页>The big and small end problem caused by union union
The big and small end problem caused by union union
2022-08-08 04:30:00 【Yulong _】
Here is a multiple choice question to find the output value:
#include #include union Test{int i;char c[3];};int main(){Test t;t.i = 20;t.c[0] = 0;t.c[1] = 0;t.c[2] = 10;printf("%d\n", t.i);system("pause");} A.20
B.655360
C.2580
D.Not sure
What should I choose?
==================================Separation Line===============================
General computers are in little endian mode. Assuming that in little endian mode, the following conditions are met:
Low address is low, high address is high
t.i = 20; //The memory layout after execution is as follows:

The memory layout after executing the following code is as follows:
t.c[0] = 0;
t.c[1] = 0;
t.c[2] = 10;

At this time, the value represented by the int type is: 0x000A0000 corresponds to the decimal system, which is 655360
Assuming big endian mode, then the following conditions are met:
High address is low, low address is high
t.i = 20; //The memory layout after execution is as follows:

The memory layout after executing the following code is as follows:
t.c[0] = 0;
t.c[1] = 0;
t.c[2] = 10;

At this time, the value represented by the int type is: 0x00000A14 corresponds to 2,580 in decimal.
To sum up, be more rigorous, you should choose D
边栏推荐
- NorFlash的存储原理
- 08 获取器 withAttr、多连缀、whereRaw、事务、数据集《ThinkPHP6 入门到电商实战》
- leetcode 70.爬楼梯 动态规划
- New retail project and offline warehouse core interview,, 220807,,
- 奇怪的魔法(组合数)
- vulnhub-DC-3靶机渗透记录
- L3-007 ladder map (test point 2 is stuck, you can see it)
- L3-007 天梯地图(测试点2卡住了可以看下)
- 2022-08-07 mysql/stonedb慢SQL-子查询-半连接
- MySql入门教程
猜你喜欢

The fledgling Xiao Li's 115th blog project notes on the creation of the domestic GD32F103RCT6 basic project

Amazon Cloud Technology Build On Learning Experience
![报错:[Intervention] Unable to preventDefault inside passive event listener due to target ...](/img/57/44e6bc7a330f075f79eb428475d89c.png)
报错:[Intervention] Unable to preventDefault inside passive event listener due to target ...

Week 4 Step by step building multi-layer neural network and application (1 & 2)

C语言-分值和循环语句

【OAuth2】十八、OIDC的认识应用

leetcode 112. Path sum recursion

10 must-have free tools for self-media people to operate quickly and efficiently

数据在内存如何分布的?

走进音视频的世界——RGB与YUV格式
随机推荐
How to avoid bugs as much as possible
XDR technology
Open3D 基于颜色的ICP配准
C语言-函数
Research on Blind Recognition of Digital Modulated Signal Based on MindSpore Framework
Week 4 Step by step building multi-layer neural network and application (1 & 2)
使用 Presto 和 Alluxio 在 AWS 上搭建高性能平台来支持实时游戏服务
多维度数组拉平到一维
风控策略必学|这种用决策树来挖掘规则的方法
拒绝“内卷”跃迁软件测试最大门槛,我是如何从月薪8K到15K的?
awk语法-03-awk表达式(if语句、while循环、for循环)、awk中执行shell命令
项目分析(嵌入式产品Web化)
Open3D ICP精配准(使用鲁棒性核函数)
【代码分析】图小样本异常检测方法:GDN:Few-shot Network Anomaly Detection via Cross-network Meta-learning
Redis持久化机制、主从、哨兵、cluster集群方案解析
MySQL4(多表查询)
一行代码统计文本中指定字符串出现的次数
Heterogeneous on the Graph paper to share 】 【 small sample learning: HG - Meta: Graph Meta - learning over Heterogeneous Graphs
中国科学院金属研究所科研课题获华为技术认证,助力材料学发展新范式!
fail-fast 和 fail-safe 快速学习