我是靠谱客的博主 谨慎咖啡豆,这篇文章主要介绍c++显示传递数组时为什么要指定其长度?,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream> const int SIZE = 5; int sum_arr(int p[],int size); int main() { int sum; int arr[SIZE] = {1,2,3,4,5}; std::cout << "sizeof (arr)=" << sizeof(arr) << ", address=" << arr <<std::endl; sum = sum_arr(arr,SIZE); std::cout << "sum of arr=" << sum <<std::endl; return 0; } int sum_arr(int p[], int size) { int sum = 0; std::cout << "sizeof (p)=" << sizeof(p) << ", address=" << p <<std::endl; for (int i =0; i < size; i++) sum += p[i]; return sum; }

 输出如下:

 

复制代码
1
2
3
4
ackerman@ubuntu:~/桌面/c++test$ ./a.out sizeof (arr)=20, address=0xbf9afa68 sizeof (p)=4, address=0xbf9afa68 sum of arr = 15
 

最后

以上就是谨慎咖啡豆最近收集整理的关于c++显示传递数组时为什么要指定其长度?的全部内容,更多相关c++显示传递数组时为什么要指定其长度内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(53)

评论列表共有 0 条评论

立即
投稿
返回
顶部