I'm a little confused when I run the code below:
int Maxi(int A[])
{
return sizeof(A)/sizeof(A[0]);
}
int main()
{
int A[5] = {1,2,3,4,5};
print("%d \n", Maxi(A));
return 0;
}
And I just get the result 2
. It seems that sizeof(A)
turns out to be 8
, which is the size of a pointer. I know this may not be a question worthy asking, but I must miss something and I just cannot figure it out right now.
But if I do this:
int main()
{
int A[5] = {1,2,3,4,5};
print("%d \n", sizeof(A)/sizeof(A[0]));
return 0;
}
It's all right then, and I thought it is related to the passage of value between functions, but I'm confused.
Thanks!