当前位置:网站首页>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个字节。
边栏推荐
- Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
- 将MySQL的表数据纯净方式导出
- HDU 2008 digital statistics
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- GD32F4XX串口接收中断和闲时中断配置
- i.mx6ull搭建boa服务器详解及其中遇到的一些问题
- Xiaoman network model & http1-http2 & browser cache
- 414. The third largest digital buckle
- 每日一题:力扣:225:用队列实现栈
- 2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
猜你喜欢

二分图判定

微信红包封面小程序源码-后台独立版-带测评积分功能源码

Oracle-控制文件及日志文件的管理

UNI-Admin基础框架怎么关闭创建超级管理员入口?

Crawler obtains real estate data

Build op-tee development environment based on qemuv8

2022-07-04 mysql的高性能数据库引擎stonedb在centos7.9编译及运行

Unity3d minigame unity webgl transform plug-in converts wechat games to use dlopen, you need to use embedded 's problem

Mise en place d'un environnement de développement OP - tee basé sur qemuv8

第3章:类的加载过程(类的生命周期)详解
随机推荐
手写ABA遇到的坑
0 basic learning C language - digital tube
(十八)LCD1602实验
Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
图像的spatial domain 和 frequency domain 图像压缩
Attack and defense world ditf Misc
Xiaoman network model & http1-http2 & browser cache
CCNA-思科网络 EIGRP协议
OpenCV VideoCapture. Get() parameter details
Powerful domestic API management tool
labelimg的安装与使用
Kohana database
MySQL约束的分类、作用及用法
[sciter]: encapsulate the notification bar component based on sciter
HDR image reconstruction from a single exposure using deep CNN reading notes
[10:00 public class]: basis and practice of video quality evaluation
MariaDB database management system learning (I) installation diagram
LeetCode 练习——剑指 Offer 26. 树的子结构
Set status bar style demo
That's why you can't understand recursion