我正在尝试将 C++ 数组作为 C++ 中的参数传递,但遇到了一些问题。我经历了这个,仍然无法解决问题。
C++
#include<iostream>
using namespace std;
void comb(int a[])
{
int alen = sizeof(a)/sizeof(*a);
cout << alen << endl;
/* Since 'I' know the size of a[] */
for(int i = 0; i < 7; i++)
cout << a[i] << " ";
cout << endl;
}
int main()
{
int a[] = {1,2,3,4,5,6,7};
comb(a);
}
Output
2
1 2 3 4 5 6 7
我的问题是数组的大小如何计算为 2?