当前位置:网站首页>数组名是首元素地址吗?
数组名是首元素地址吗?
2022-07-27 14:27:00 【发发是只呆头鹅】
数组名确实是首元素地址,但是有两个例外。
1.sizeof(数组名),这里的数组名不是首元素地址,是表示整个数组。
上代码:
int arr[10] = {
0 };
printf("%d\n", sizeof(arr));
打印结果为:
如果是首元素的地址,在32位平台地址的大小是4个字节,64位平台地址大小为8个字节,但是这里的输出结果是40字节,所以sizeof(数组名)这种情况,数组名代表的是整个数组。
2.&数组名,这里的数组名也表示的是整个数组。
上代码:
int arr[10] = {
0 };
printf("%p\n", &arr);
printf("%p\n", &arr[0]);
printf("%p\n", &arr[0]+1);
printf("%p\n", &arr+1);
打印结果为:
&arr[0]和&arr[0]+1分别表示数组arr的首元素地址和第一个元素的地址,其差值为4,正好是一个整形的大小,我们再看&arr和&arr+1的差值为40,,正好是10个整形的大小,所以&arr中的arr表示的是整个数组。
边栏推荐
- C:浅谈函数
- Leetcode 81. search rotation sort array II binary /medium
- [正则表达式] 单个字符匹配
- 【剑指offer】面试题41:数据流中的中位数——大、小堆实现
- JS find the maximum and minimum values in the array (math.max() method)
- Network equipment hard core technology insider router Chapter 4 Jia Baoyu sleepwalking in Taixu Fantasy (Part 2)
- EMC design scheme of USB2.0 Interface
- Leetcode 783. binary search tree node minimum distance tree /easy
- Several basic uses of tl431-2.5v voltage reference chip
- 使用Prometheus监控Spark任务
猜你喜欢

Singles cup, web:web check in

初识结构体

Leetcode-1737-满足三条件之一需改变的最少字符数

Fluent -- layout principle and constraints

With just two modifications, apple gave styleganv2 3D generation capabilities

Leetcode 74. search two-dimensional matrix bisection /medium

How to package AssetBundle

C语言:动态内存函数

【剑指offer】面试题53-Ⅰ:在排序数组中查找数字1 —— 二分查找的三个模版

EMC design scheme of RS485 interface
随机推荐
Adaptation verification new occupation is coming! Huayun data participated in the preparation of the national vocational skill standard for information system adaptation verifiers
Leetcode 190. reverse binary bit operation /easy
【剑指offer】面试题46:把数字翻译成字符串——动态规划
【剑指offer】面试题41:数据流中的中位数——大、小堆实现
Network equipment hard core technology insider router Chapter 5 tompkinson roaming the network world (Part 1)
后台返回来的是这种数据,是什么格式啊
聊聊面试必问的索引
Network equipment hard core technology insider router Chapter 14 from deer by device to router (middle)
实现自定义Spark优化规则
一文读懂鼠标滚轮事件(wheelEvent)
Network equipment hard core technology insider router Chapter 11 Cisco asr9900 disassembly (V)
Discussion on STM32 power down reset PDR
After configuring corswebfilter in grain mall, an error is reported: resource sharing error:multiplealloworiginvalues
Pictures to be delivered
[正则表达式] 单个字符匹配
Leetcode 81. search rotation sort array II binary /medium
Tools - common methods of markdown editor
NPM install error unable to access
The first common node of the two linked lists of "Jianzhi offer"
STM32F10x_ Hardware I2C read / write EEPROM (standard peripheral library version)