当前位置:网站首页>2.57-编写程序show_short, show_long和show_double,它们分别打印类型为short, long和double的C语言对象的字节表示。请试着在几种机器上运行。
2.57-编写程序show_short, show_long和show_double,它们分别打印类型为short, long和double的C语言对象的字节表示。请试着在几种机器上运行。
2022-04-22 21:49:00 【gan-di】
#include <stdio.h>
//A byte pointer refers to a sequence of bytes
typedef unsigned char * byte_pointer;
//The input is a byte pointer and a byte number
void show_bytes(byte_pointer start, size_t len) {
size_t i;
for (i = 0; i < len; i++) {
//A storage unit holds one byte
printf("%.2x ", start[i]);
//Output in hexadecimal format with at least two digits
}
printf("\n");
}
//show_short
void show_short(short x) {
show_bytes((byte_pointer)&x, sizeof(short));
}
//show_long
void show_long(long x) {
show_bytes((byte_pointer)&x, sizeof(long));
}
//show_double
void show_double(double x) {
show_bytes((byte_pointer)&x, sizeof(double));
}
void show_pointer(void *x) {
show_bytes((byte_pointer)&x, sizeof(void *));
}
void test_show_bytes(int val) {
//Prints byte representations of the three target types
int ival = val;
short stval = (short)ival;
long lval = (long)ival;
double dval = (double)ival;
show_short(stval);
show_long(lval);
show_double(dval);
}
int main() {
int test = 328;
test_show_bytes(test);
return 0;
}
win64 中long占4个字节

linux64 中long占8个字节

版权声明
本文为[gan-di]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45861496/article/details/124306047
边栏推荐
- R language uses rjags and r2jags to establish Bayesian model
- They are all intelligent in the whole house. What's the difference between aqara and homekit?
- What are the functional problems of UI testing?
- 一夜爆红的Moonbirds NFT,究竟有何魔力?
- RPCX源码学习-client端
- 4 / 21 Kunming supplementary questions + mathematics
- Why is bi so important to enterprises?
- 秒云助力中电科32所发布“基于拟态应用集成框架的SaaS云管理平台解决方案”
- JS solving power deduction daily question (8) -- 396 Rotation function (2022-4-22)
- Crashsight general function & feature function introduction
猜你喜欢

ATOS阿托斯比例阀的工作原理及主要特性概述
![[Istio是什么?] 还不知道你就out了,一文40分钟快速理解](/img/c4/07d319932bddf2eede47bd2078f777.png)
[Istio是什么?] 还不知道你就out了,一文40分钟快速理解

赛微微电上市首日破发:市值蒸发超15亿元,经营规模略输一筹

Flex layout

Is it necessary to read the history of mathematics? We have neglected too much about mathematics education

Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind

一夜爆红的Moonbirds NFT,究竟有何魔力?

The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video

OSPF detailed explanation, classification and experimental explanation

Resource packaging dependency tree
随机推荐
水平低的团队还是别用typescript了
Reference policy example explanation
Overview of working principle and main characteristics of ATOS proportional valve
R language uses rjags and r2jags to establish Bayesian model
阿里云日志服务sls的典型应用场景
LeetCode-238-除自身以外数组的乘积
JS solving power deduction daily question (8) -- 396 Rotation function (2022-4-22)
Web测试需要注意什么?
PHP wechat refund certificate
Yapi本地部署
企业应如何制定云计算使用中的灾难恢复计划?
工业互联网创新迭代的推手
如何使用 Lightly 优雅地上编程课?
JD side: how can a child thread get the value of the parent thread ThreadLocal? I got...
pcba/ IPQ6010 802.11ax 2x2 2.4G&5G /2.5Gbps Ethernet Port
Pushing hand of industrial Internet innovation iteration
跨域问题及Umi-proxy代理解决跨域问题
hawe哈威液压泵站的液压冲击分析
Transport layer - connectionless transport: UDP (2)
Hydraulic shock analysis of haWe haWe hydraulic pump station