Possible Duplicate:
Sizeof array passed as parameter
Given the following code, the system I'm currently on (which seems to be 64-bit given the size of a pointer) prints:
32
4
Now, the size of an int should be 4 bytes on this system, so 8*4 = 32 makes sense. Also, I understand that the size of a pointer should also be 4 bytes, which is what I'm guessing is happening to the array in foo.
My question is why is sizeof(arr) in the foo function treated differently than sizeof(myarray) in main() when both are specifically int[8] arrays? I had anticipated receiving 32 in both cases and it confuses me why it would end up otherwise.
#include <iostream>
void foo(int arr[8])
{
std::cerr << sizeof(arr) << std::endl;
}
int main()
{
int myarray[8];
std::cerr << sizeof(myarray) << std::endl
foo(myarray);
}