当前位置:网站首页>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个字节。
边栏推荐
- GNN,请你的网络层数再深一点~
- Assembly and interface technology experiment 5-8259 interrupt experiment
- [sciter bug] multi line hiding
- 解决项目跨域问题
- Management background --3, modify classification
- 中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
- CCNA-思科网络 EIGRP协议
- Assembly and Interface Technology Experiment 6 - ADDA conversion experiment, AD acquisition system in interrupt mode
- 2500 common Chinese characters + 130 common Chinese and English characters
- Chapter 4: talk about class loader again
猜你喜欢

2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
The SQL response is slow. What are your troubleshooting ideas?

Attack and defense world ditf Misc

NetXpert XG2帮您解决“布线安装与维护”难题

硬件開發筆記(十): 硬件開發基本流程,制作一個USB轉RS232的模塊(九):創建CH340G/MAX232封裝庫sop-16並關聯原理圖元器件

Chapter 3: detailed explanation of class loading process (class life cycle)

Xiaoman network model & http1-http2 & browser cache

Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
![[leetcode daily clock in] 1020 Number of enclaves](/img/2d/3d12f20c8c73fb28044c01be633c99.jpg)
[leetcode daily clock in] 1020 Number of enclaves

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?
十二、启动流程
Force buckle 575 Divide candy
Oracle Performance Analysis 3: introduction to tkprof
【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真
GPS from getting started to giving up (12), Doppler constant speed
Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
2022-07-04 mysql的高性能数据库引擎stonedb在centos7.9编译及运行
Report on technological progress and development prospects of solid oxide fuel cells in China (2022 Edition)
Daily question 1: force deduction: 225: realize stack with queue
[linear algebra] determinant of order 1.3 n
C#实现水晶报表绑定数据并实现打印4-条形码
Web APIs DOM 时间对象
Unity3d Learning Notes 6 - GPU instantiation (1)
Aardio - 封装库时批量处理属性与回调函数的方法
Applet system update prompt, and force the applet to restart and use the new version
MySQL约束的分类、作用及用法
新手程序员该不该背代码?
Assembly and interface technology experiment 5-8259 interrupt experiment
GNN,请你的网络层数再深一点~