Possible Duplicate:
Calculating size of an array
Sizeof an array in the C programming language?
Why does sizeof(arr)/(double)sizeof(arr[0])
work and sizeof(arr+0)/(double)sizeof(arr[0])
not work?
And why does sizeof(arr)/(double)sizeof(arr[0])
also not work when arr is passed to a function? Here is the full code example:
#include <iostream>
using namespace std;
int givesize(int arr[])
{
cout<<sizeof(arr)/(double)sizeof(arr[0])<<"\n";
}
int main()
{
int arr[] = {1,2,3,4,5};
cout<<sizeof(arr)/(double)sizeof(arr[0])<<"\n";
cout<<sizeof(arr+2)/(double)sizeof(arr[0])<<"\n";
givesize(arr);
return 0;
}
Output 5 1 1