当前位置:网站首页>Sizeof keyword
Sizeof keyword
2022-07-06 22:31:00 【It's Beichen not too PI acridine】
sizeof keyword
1.sizeof It's a keyword, not a function , It is 32 One of the keywords .
2.sizeof When calculating the space occupied by variables , Brackets can be omitted , Calculation type ( Mold ) Size cannot be omitted . In general , Let's not steal this lazy , Write brackets obediently .
3.sizeof The returned footprint is the size opened up for this variable , Not the space it uses . So when it comes to structures , In most cases, we have to consider the problem of byte alignment .
4.sizeof The data type returned is unsigned int; An unsigned number and a signed number operation , Most compilers convert to unsigned type operations .
5. Pay attention to the difference between array names and pointer variables . Usually , We always think that array names are similar to pointer variables , But in use sizeof It's very different when , Use... For array names sizeof Returns the size of the entire array , When operating on a pointer variable, the return is the space occupied by the pointer variable itself , stay 32 Under the condition of bit machine, it is generally 4 byte . And when the array name is used as a function parameter , Inside the function , A formal parameter is just a pointer , So no longer return the size of the array .
sizeof(int)*p What do you mean ?
answer : For calculation int Number of bytes occupied by type , And then multiply by p.
32 A system. :
The pointer size is determined by the current CPU The addressing bits of the operation mode determine .Intel 32 Bit processor 32 Bit operation mode , Logical addressing bits 32, The pointer is 32 position , namely 4 Bytes .Intel 32 Bit processor 16 Bit virtual machine operation mode , Logical addressing bits 16, The pointer is 16 position , namely 2 Bytes .
int *p = NULL;
sizeof( p ) What's the value of ?
answer : Pointer address is used DWORD, sizeof( p ) yes 4 byte
sizeof(*p) Well ?
answer : be equal to sizeof(int) , Probably yes 2 byte It could be 4 byte
(DWORD Namely Double Word, Every word by 2 The length of bytes ,DWORD Double word is 4 Bytes , Each byte is 8 position , common 32 position .)
int a[100];
sizeof (a) What's the value of ?
answer :sizeof(a) = sizeof(int) * 100 = 4 * 100 = 400 byte
sizeof(a[99]) Well ?
answer : Please 100 The size of an element , use int Deposit , Occupy 4 Bytes
sizeof(&a) Well ?
answer : Means to store a The size of the address space and memory address , namely &a It's also an address value . An address is used int Storage is also 4 Bytes
sizeof(&a[0]) Well ?
answer : Take the address of the first element , use int Deposit , Occupy 4 Bytes
int b[100];
void fun(int b[100])
{
sizeof(b);
}
sizeof (b) What's the value of ?
answer :fun In the parameter list b It's a pointer , stay 32 Bit system , The pointer is always 4 Bytes .
边栏推荐
- Daily question 1: force deduction: 225: realize stack with queue
- 软考高级(信息系统项目管理师)高频考点:项目质量管理
- 中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
- [linear algebra] determinant of order 1.3 n
- 云原生技术--- 容器知识点
- volatile关键字
- UDP programming
- ThreadLocal详解
- Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
- SQL server generates auto increment sequence number
猜你喜欢
0 basic learning C language - digital tube
ResNet-RS:谷歌领衔调优ResNet,性能全面超越EfficientNet系列 | 2021 arxiv
That's why you can't understand recursion
config:invalid signature 解决办法和问题排查详解
机试刷题1
Aardio - 通过变量名将变量值整合到一串文本中
Build op-tee development environment based on qemuv8
AdaViT——自适应选择计算结构的动态网络
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
Improving Multimodal Accuracy Through Modality Pre-training and Attention
随机推荐
柔性数组到底如何使用呢?
Seata聚合 AT、TCC、SAGA 、 XA事务模式打造一站式的分布式事务解决方案
MySQL----初识MySQL
【LeetCode】19、 删除链表的倒数第 N 个结点
Management background --4, delete classification
Should novice programmers memorize code?
void关键字
中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
volatile关键字
SQL server generates auto increment sequence number
Mise en place d'un environnement de développement OP - tee basé sur qemuv8
AdaViT——自适应选择计算结构的动态网络
BasicVSR_PlusPlus-master测试视频、图片
雅思口语的具体步骤和时间安排是什么样的?
[leetcode] 19. Delete the penultimate node of the linked list
[Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation
Management background --5, sub classification
小程序系统更新提示,并强制小程序重启并使用新版本
Gd32f4xx serial port receive interrupt and idle interrupt configuration
机试刷题1