当前位置:网站首页>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个字节。
边栏推荐
- Daily question 1: force deduction: 225: realize stack with queue
- HDU 2008 digital statistics
- anaconda安装第三方包
- Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
- Memorabilia of domestic database in June 2022 - ink Sky Wheel
- 0 basic learning C language - interrupt
- 2021 geometry deep learning master Michael Bronstein long article analysis
- 硬件開發筆記(十): 硬件開發基本流程,制作一個USB轉RS232的模塊(九):創建CH340G/MAX232封裝庫sop-16並關聯原理圖元器件
- 将MySQL的表数据纯净方式导出
- MariaDB database management system learning (I) installation diagram
猜你喜欢
Learn the principle of database kernel from Oracle log parsing
Aardio - 利用customPlus库+plus构造一个多按钮组件
pytorch_YOLOX剪枝【附代码】
UNI-Admin基础框架怎么关闭创建超级管理员入口?
That's why you can't understand recursion
How does the uni admin basic framework close the creation of super administrator entries?
0 basic learning C language - interrupt
重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
Classic sql50 questions
GNN,请你的网络层数再深一点~
随机推荐
网络基础入门理解
2500个常用中文字符 + 130常用中英文字符
Chapter 3: detailed explanation of class loading process (class life cycle)
Management background --3, modify classification
[10:00 public class]: basis and practice of video quality evaluation
12、 Start process
[leetcode daily clock in] 1020 Number of enclaves
HDR image reconstruction from a single exposure using deep CNNs阅读札记
MySQL约束的分类、作用及用法
3DMax指定面贴图
Barcodex (ActiveX print control) v5.3.0.80 free version
Oracle Performance Analysis 3: introduction to tkprof
Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
Report on technological progress and development prospects of solid oxide fuel cells in China (2022 Edition)
Unity3d Learning Notes 6 - GPU instantiation (1)
Force buckle 575 Divide candy
中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
qt quick项目offscreen模式下崩溃的问题处理
HDU 4912 paths on the tree (lca+)