当前位置:网站首页>sizeof关键字
sizeof关键字
2022-07-06 14:40:00 【是北豼不太皮吖】
sizeof关键字
1.sizeof 是关键字不是函数,它是 32 个关键字之一。
2.sizeof 在计算变量所占空间大小时,括号可以省略,而计算类型(模子)大小时不能省略。一般情况下,咱也别偷这个懒,乖乖的写上括号。
3.sizeof返回的占用空间大小是为这个变量开辟的大小,而不是它用到的空间。所以对结构体用的时候,大多情况下得考虑字节对齐的问题了。
4.sizeof返回的数据类型是unsigned int;一个无符号的数和有符号的数运算,大多编译器都是转化成无符号类型运算。
5.要注意数组名和指针变量的区别。通常情况下,我们总觉得数组名和指针变量差不多,但是在用sizeof的时候差别很大,对数组名用sizeof返回的是整个数组的大小,而对指针变量进行操作的时候返回则是指针变量本身所占的空间,在32位机的条件下一般都是4字节。而且当数组名作为函数参数时,在函数内部,形参也就是个指针,所以不再返回数组的大小。
sizeof(int)*p 表示什么意思?
答:表示计算int型所占字节数,然后再乘以p。
32 位系统下:
指针大小是由当前CPU运行模式的寻址位数决定。Intel 32位处理器32位运行模式,逻辑寻址位数32,指针也就是32位,即4个字节。Intel 32位处理器16位虚拟机运行模式,逻辑寻址位数16,指针也就是16位,即2个字节。
int *p = NULL;
sizeof( p )的值是多少?
答:指针地址用 DWORD, sizeof( p ) 是 4字节
sizeof(*p)呢?
答:等于 sizeof(int) ,可能 是 2字节 也可能是 4字节
(DWORD 就是 Double Word, 每个word为2个字节的长度,DWORD 双字即为4个字节,每个字节是8位,共32位。)
int a[100];
sizeof (a) 的值是多少?
答:sizeof(a) = sizeof(int) * 100 = 4 * 100 = 400字节
sizeof(a[99])呢?
答:求第100个元素的大小 ,用int存放,占用4个字节
sizeof(&a)呢?
答:表示存放a的地址的空间内存的地址的大小,即&a也是个地址值。一个地址用int存放也是4个字节
sizeof(&a[0])呢?
答:取第一个元素的地址,用int存放,占用4个字节
int b[100];
void fun(int b[100])
{
sizeof(b);
}
sizeof (b) 的值是多少?
答:fun参数列表中的b是一个指针,在32位系统中,指针永远是4个字节。
边栏推荐
- Problems in the process of opencv300 cmake generating project
- 基于 QEMUv8 搭建 OP-TEE 开发环境
- 小程序系统更新提示,并强制小程序重启并使用新版本
- Notes de développement du matériel (10): flux de base du développement du matériel, fabrication d'un module USB à RS232 (9): création de la Bibliothèque d'emballage ch340g / max232 SOP - 16 et Associa
- extern关键字
- 新手程序员该不该背代码?
- 手写ABA遇到的坑
- Common sense: what is "preservation" in insurance?
- 【10点公开课】:视频质量评价基础与实践
- Maximum product of three numbers in question 628 of Li Kou
猜你喜欢
Oracle control file and log file management
PVL EDI project case
Installation and use of labelimg
3DMax指定面贴图
AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
CCNA-思科网络 EIGRP协议
Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
图像的spatial domain 和 frequency domain 图像压缩
2021 geometry deep learning master Michael Bronstein long article analysis
Senior soft test (Information System Project Manager) high frequency test site: project quality management
随机推荐
CCNA Cisco network EIGRP protocol
AI 企业多云存储架构实践 | 深势科技分享
做接口测试都测什么?有哪些通用测试点?
Xiaoman network model & http1-http2 & browser cache
AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
Assembly and interface technology experiment 5-8259 interrupt experiment
Common sense: what is "preservation" in insurance?
Codeforces Round #274 (Div. 2) –A Expression
墨西哥一架飞往美国的客机起飞后遭雷击 随后安全返航
Research and investment strategy report of China's VOCs catalyst industry (2022 Edition)
Support multiple API versions in flask
VIP case introduction and in-depth analysis of brokerage XX system node exceptions
ZABBIX proxy server and ZABBIX SNMP monitoring
小程序系统更新提示,并强制小程序重启并使用新版本
i.mx6ull搭建boa服务器详解及其中遇到的一些问题
OpenCV VideoCapture. Get() parameter details
软考高级(信息系统项目管理师)高频考点:项目质量管理
Set status bar style demo
GNN,请你的网络层数再深一点~
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件