See Question 6.4 and 6.21 in the C FAQ
Q: Why doesn't sizeof properly report the size of an array when the array is a parameter to a function? I have a test routine
f(char a[10])
{
int i = sizeof(a);
printf("%d\n", i);
}
and it prints 4, not 10.
A: The compiler pretends that the array parameter was declared as a pointer (that is, in the example, as char *a; see question 6.4), and sizeof reports the size of the pointer. See also questions 1.24 and 7.28.
This is what 7.28 says:
Q: Why doesn't sizeof
tell me the size of the block of memory pointed to by a pointer?
A: sizeof
tells you the size of the pointer. There is no portable way to find out the size of a malloc'ed block. (Remember, too, that sizeof operates at compile time, and see also question 7.27.)