当前位置:网站首页>[C language errata] error in getting array length in function
[C language errata] error in getting array length in function
2022-07-19 03:41:00 【Tomorrowave】
How do we usually get the length of the array ?
Because the type of each element in the array is the same , The number of bytes in memory is the same , So the total number of bytes divided by the number of bytes occupied by an element is the length of the array .
int arr={
1,2,3,4,5,6}
int len = sizeof(arr)/sizeof(arr[0]); //6
Code up
because , The array passed in is the function parameter , In this function , Array is just a pointer ( Address , When the system runs this function , I don't know how much data storage space the address represented by the array has This is just to tell the function : The first address of a data storage space ), So the result is that the pointer variable occupies the memory size
void Reverse(int* arr)
{
int len=sizeof(arr)/(sizeof(arr[0]));
cout<<sizeof(arr)<<endl;
cout<<sizeof(arr[0])<<endl;
}

边栏推荐
- Rhce8 Study Guide Chapter 2 use of basic commands
- Shell script receives and returns parameters
- Thinkphp5.0模型操作使用page进行分页
- Digital type processing and convenient method of ext JS
- 爬虫学习(5):手把手教你爬虫requests实战演练
- Qt OpenGL 通过鼠标和键盘移动三维物体(设置相机)
- leetcode:50. Pow(x, n)
- Thinkphp5.0 model operation uses page for paging
- 论文阅读:U-Net++: Redesigning Skip Connections to Exploit Multiscale Features in Image Segmentation
- 第二章 线性表
猜你喜欢

ResNet

波士顿房价分析作业总结

Derivation of PCA principal component analysis (dimension reduction) process

ES6 learning notes - brother Ma at station B

Thinkphp5.0模型操作使用page进行分页

ES6學習筆記——B站小馬哥

Thinkphp5.0 model operation uses page for paging

374. 猜数字大小(入门 必会)

ulsm配置案例
![[NoSQL] redis configuration and optimization of NoSQL (simple operation)](/img/e4/dcfeb675fd0ff4be3687547b28048d.png)
[NoSQL] redis configuration and optimization of NoSQL (simple operation)
随机推荐
Go语言中的Iota关键字怎么使用
The third day of the three questions of Luogu daily (make up on the fourth day)
Detailed explanation of arrow function and this direction
Chengxin University envi_ IDL second week class content: open hdf4 file and read the file, as well as simple data processing and saving + detailed analysis
module_ Basic principle of init function
ES6學習筆記——B站小馬哥
Machine learning library scikit learn (linear model, ridge regression, insert a column of data, extract the required column, vector machine (SVM), clustering)
[2016 CCPC 杭州J] Just a Math Problem (莫比乌斯反演)
Note: light source selection and Application
运算符、赋值语句、结构说明语句
oracle 查询非自增长分区的最大分区
MYSQL主从搭建
Vs code problem: launch:program '... \ vscode\launch. exe‘ dose not exist
Use RZ, SZ commands to upload and download files through xshell7
一种鲁棒变形卷积神经网络图像去噪
Pure virtual function
Dive Into Deep Learning——2.2数据预处理
未知宽高元素实现水平垂直居中的方法
Chengxin University envi_ The second week of IDL experiment content: extract aod+ in all MODIS aerosol products for detailed analysis
Solve the error of 0x00000709 when win10 connects to the shared printer