主题:[讨论]大家来看看一个简短的程序,求原因
在写程序的时候碰到了点问题, 然后我就写了下面的实验代码, 输出结果是:
The number of elements of the array is :10
The number of elements of the array is :1
请按任意键继续. . .
同一个数组, 我只不过是放到不同的函数里处理, 为什么会有不同的结果?
#include <iostream>
using namespace std;
void CheckSize(int Array[])
{
cout<<"The number of elements of the array is :"<<sizeof Array / sizeof Array[0]<<endl;
}
void main()
{
const int size = 10;
int Array[10];
cout<<"The number of elements of the array is :"<< sizeof Array / sizeof Array[0]<<endl;
CheckSize(Array);
}
The number of elements of the array is :10
The number of elements of the array is :1
请按任意键继续. . .
同一个数组, 我只不过是放到不同的函数里处理, 为什么会有不同的结果?
#include <iostream>
using namespace std;
void CheckSize(int Array[])
{
cout<<"The number of elements of the array is :"<<sizeof Array / sizeof Array[0]<<endl;
}
void main()
{
const int size = 10;
int Array[10];
cout<<"The number of elements of the array is :"<< sizeof Array / sizeof Array[0]<<endl;
CheckSize(Array);
}