当前位置:网站首页>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 .
边栏推荐
- 【LeetCode】19、 删除链表的倒数第 N 个结点
- Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
- rust知识思维导图xmind
- [leetcode] 19. Delete the penultimate node of the linked list
- 小程序系统更新提示,并强制小程序重启并使用新版本
- Advantages of link local address in IPv6
- 3DMAX assign face map
- Self made j-flash burning tool -- QT calls jlinkarm DLL mode
- SQL Server生成自增序号
- Lora sync word settings
猜你喜欢
Learn the principle of database kernel from Oracle log parsing
pytorch_YOLOX剪枝【附代码】
signed、unsigned关键字
二分图判定
Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
Management background --1 Create classification
[leetcode daily clock in] 1020 Number of enclaves
树的先序中序后序遍历
Memorabilia of domestic database in June 2022 - ink Sky Wheel
PVL EDI 项目案例
随机推荐
void关键字
Memorabilia of domestic database in June 2022 - ink Sky Wheel
SQL server generates auto increment sequence number
BasicVSR_PlusPlus-master测试视频、图片
The nearest common ancestor of binary (search) tree ●●
Management background --5, sub classification
three.js绚烂的气泡效果
剪映+json解析将视频中的声音转换成文本
Anaconda installs third-party packages
General implementation and encapsulation of go diversified timing tasks
MySQL教程的天花板,收藏好,慢慢看
做接口测试都测什么?有哪些通用测试点?
基於 QEMUv8 搭建 OP-TEE 開發環境
中国固态氧化物燃料电池技术进展与发展前景报告(2022版)
Research and investment strategy report of China's VOCs catalyst industry (2022 Edition)
Aardio - 不声明直接传float数值的方法
3DMAX assign face map
新手程序员该不该背代码?
What are the specific steps and schedule of IELTS speaking?
uniapp滑动到一定的高度后固定某个元素到顶部效果demo(整理)