当前位置:网站首页>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 .
边栏推荐
- signed、unsigned关键字
- What are the specific steps and schedule of IELTS speaking?
- RESNET rs: Google takes the lead in tuning RESNET, and its performance comprehensively surpasses efficientnet series | 2021 arXiv
- 2022-07-05 stonedb sub query processing parsing time analysis
- Management background --3, modify classification
- Unity3d minigame unity webgl transform plug-in converts wechat games to use dlopen, you need to use embedded 's problem
- leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
- 图像的spatial domain 和 frequency domain 图像压缩
- Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
- Crawler obtains real estate data
猜你喜欢

Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
![[leetcode] 19. Delete the penultimate node of the linked list](/img/ab/25cb6d6538ad02d78f7d64b2a2df3f.png)
[leetcode] 19. Delete the penultimate node of the linked list

Clip +json parsing converts the sound in the video into text

3DMAX assign face map

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

Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution

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

Assembly and interface technology experiment 5-8259 interrupt experiment

如何用程序确认当前系统的存储模式?

第3章:类的加载过程(类的生命周期)详解
随机推荐
Advantages of link local address in IPv6
Research and investment strategy report of China's VOCs catalyst industry (2022 Edition)
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
The ceiling of MySQL tutorial. Collect it and take your time
Crawler obtains real estate data
Applet system update prompt, and force the applet to restart and use the new version
【编译原理】做了一半的LR(0)分析器
sizeof关键字
extern关键字
AdaViT——自适应选择计算结构的动态网络
(18) LCD1602 experiment
NPDP certification | how do product managers communicate across functions / teams?
雅思口语的具体步骤和时间安排是什么样的?
uniapp设置背景图效果demo(整理)
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
Mysql database basic operations DML
网络基础入门理解
云原生技术--- 容器知识点
NetXpert XG2帮您解决“布线安装与维护”难题
[leetcode] 19. Delete the penultimate node of the linked list