当前位置:网站首页>[C语言勘误]数组长度的函数内获取方式错误
[C语言勘误]数组长度的函数内获取方式错误
2022-07-17 01:33:00 【Tomorrowave】
我们平时都是怎么获取数组长度的?
因为数组中每个元素的类型都是一样的,在内存中所占的字节数都是相同的,所以总的字节数除以一个元素所占的字节数就是数组的长度。
int arr={
1,2,3,4,5,6}
int len = sizeof(arr)/sizeof(arr[0]); //6
上代码
因为,传入的数组是函数参数,到了本函数中,数组只是一个指针(地址,系统在本函数运行时,是不知道数组所表示的地址有多大的数据存储空间 这里只是告诉函数:一个数据存储空间首地址),所以结果是指针变量占内存大小
void Reverse(int* arr)
{
int len=sizeof(arr)/(sizeof(arr[0]));
cout<<sizeof(arr)<<endl;
cout<<sizeof(arr[0])<<endl;
}

边栏推荐
- Leetcode: dynamic programming [basic problem solving]
- 2022-07-16: what is the output of the following go language code? A:[]; B:[5]; C:[5 0 0 0 0]; D:[0 0 0 0 0]。 package main import ( “fmt“ )
- Visual analysis of ncnn param file and bin model
- Thinkphp5.0模型操作使用page进行分页
- Rhce8 Study Guide Chapter 2 use of basic commands
- ES6学习笔记——B站小马哥
- Leetcode: 0-1 knapsack problem in dynamic programming [come and set the template directly]
- Flutter development: running the flutter upgrade command reports an error exception:flutter failed to create a directory at... Solution
- Paper reading: u-net++: redesigning skip connections to exploit multiscale features in image segmentation
- Zabbix6.0 monitors Dell and IBM server hardware through Idrac and imm2
猜你喜欢

通过Dao投票STI的销毁,SeekTiger真正做到由社区驱动

How to read and write a single document based on MFC

基于MFC如何实现单个文档的文件读写

IEEE754 standard floating point format

Number of supported question banks and examination question banks of swiftui examination question bank project (tutorial includes source code)

Flutter development: running the flutter upgrade command reports an error exception:flutter failed to create a directory at... Solution

ES6 learning notes - brother Ma at station B

Envi: (the most detailed tutorial in 2022) custom coordinate system

Browser cannot open tensorboard
![Theoretical basis of doubledqn and its code implementation [pytoch + pendulum-v0]](/img/f2/4a3cc8e5173789111080915aceb9fd.png)
Theoretical basis of doubledqn and its code implementation [pytoch + pendulum-v0]
随机推荐
10. Redis 面试常见问答
Win10 network connection shows no network but Internet access
Ext JS的数字类型处理及便捷方法
Binary search (leetcode704. very simple and necessary)
[NoSQL] redis high availability and persistence
Oracle queries the host name and the corresponding IP address
二分查找(leetcode704.很简单必会的)
Rewrite equals why rewrite hashcode
Leetcode: dynamic programming [basic problem solving]
运算符、赋值语句、结构说明语句
Browser cannot open tensorboard
The third day of the three questions of Luogu daily (make up on the fourth day)
[MySQL] data query operation (select statement)
Number of supported question banks and examination question banks of swiftui examination question bank project (tutorial includes source code)
oracle 关闭回收站
Chapter II linear table
Oracle queries the maximum partition of non self growing partition
SwiftUI 考试题库项目之支持题库和考试题库数量(教程含源码)
未知宽高元素实现水平垂直居中的方法
laravel的问题