当前位置:网站首页>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个字节。
边栏推荐
- [Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation
- Inno Setup 打包及签名指南
- How does the uni admin basic framework close the creation of super administrator entries?
- Save and retrieve strings
- [10:00 public class]: basis and practice of video quality evaluation
- Shortcut keys in the terminal
- 剪映+json解析将视频中的声音转换成文本
- Kohana database
- HDU 4912 paths on the tree (lca+)
- qt quick项目offscreen模式下崩溃的问题处理
猜你喜欢
![[10:00 public class]: basis and practice of video quality evaluation](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[10:00 public class]: basis and practice of video quality evaluation

PVL EDI project case

Management background --1 Create classification

Aardio - 封装库时批量处理属性与回调函数的方法

zabbix 代理服务器 与 zabbix-snmp 监控

MySQL数据库基本操作-DML

Aardio - 不声明直接传float数值的方法

Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings

图像的spatial domain 和 frequency domain 图像压缩

【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真
随机推荐
PVL EDI project case
Research and investment strategy report of China's VOCs catalyst industry (2022 Edition)
Crawler obtains real estate data
Mongodb (III) - CRUD
The nearest common ancestor of binary (search) tree ●●
Codeforces Round #274 (Div. 2) –A Expression
微信红包封面小程序源码-后台独立版-带测评积分功能源码
Chapter 4: talk about class loader again
0 basic learning C language - interrupt
China 1,4-cyclohexanedimethanol (CHDM) industry research and investment decision-making report (2022 Edition)
中国VOCs催化剂行业研究与投资战略报告(2022版)
C # réalise la liaison des données du rapport Crystal et l'impression du Code à barres 4
Common sense: what is "preservation" in insurance?
枚举与#define 宏的区别
[sciter bug] multi line hiding
剪映+json解析将视频中的声音转换成文本
Assembly and Interface Technology Experiment 6 - ADDA conversion experiment, AD acquisition system in interrupt mode
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
Kohana database
The SQL response is slow. What are your troubleshooting ideas?