当前位置:网站首页>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
边栏推荐
- MySQL4(多表查询)
- QMI8658 - 6轴传感器学习笔记 - Ⅱ
- Usage of topk()/eq( ) / gt( ) / lt( ) / t( )
- cube-studio 部署过程
- 分类、目标检测、语义分割、实例分割的区别
- 6G-Oriented Communication Perception Integrated Architecture and Key Technologies
- The storage principle of NorFlash
- Mini Program Optimization Practice
- 2022-08-07 mysql/stonedb慢SQL-子查询-半连接
- 【论文分享】异质图上的小样本学习:HG-Meta: Graph Meta-learning over Heterogeneous Graphs
猜你喜欢

国内最主流的5大项目工时管理系统

32. Do you know how Redis strings are implemented?

XDR技术

Risk control strategy must be learned | This method of mining rules with decision trees

MySQL4(多表查询)

一行代码统计文本中指定字符串出现的次数

y90. Chapter 6 Microservices, Service Grids and Envoy Combat -- Service Grid Basics (1)

使用 Presto 和 Alluxio 在 AWS 上搭建高性能平台来支持实时游戏服务

vulnhub-DC-5 target drone penetration record

Shell 脚本 — 多行注释、开启子/不开启子进程执行、转义带颜色输出、读取键盘输入、输入输出重定向、单双引号、命令替换、读取变量、系统变量、正则过滤、算术运算、一行多条命令、字符串比较
随机推荐
Heterogeneous on the Graph paper to share 】 【 small sample learning: HG - Meta: Graph Meta - learning over Heterogeneous Graphs
Redis持久化机制、主从、哨兵、cluster集群方案解析
MySQL从入门到入土【20W字收藏篇】
拒绝“内卷”跃迁软件测试最大门槛,我是如何从月薪8K到15K的?
Monitoring tool Prometheus and project summary, 220805,,
【多任务CTR】阿里ESMM:Entire Space Multi-Task Model: An Effective Approach for Estimating Post-Click Conve
NetCore uses Dapper to query data
10款自媒体人必备的免费工具,快速高效运营
NorFlash的存储原理
The live broadcast of agricultural products continues to heat up, Economic Daily: Don’t forget quality when rushing
Redis persistence mechanism, master-slave, sentry, cluster parsing cluster solution
C语言 扫雷
shell原地更新终端输出信息
The use of mmedicting get_flops. Py
Qt 事件学习参考的一些优秀博客推荐
Young freshmen who yearn for open source | The guide to avoiding pits from open source to employment is here!
Awk syntax-03-awk expressions (if statements, while loops, for loops), execute shell commands in awk
A line of code counts the number of occurrences of the specified string in the text
【代码分析】图小样本异常检测方法:GDN:Few-shot Network Anomaly Detection via Cross-network Meta-learning
OLTP和OLAP问题的个人总结