int main()
{
int *pArray;
int array[10];
pArray = (int*)malloc( sizeof *pArray * 10 );
int n = sizeof(pArray);
int m = sizeof(array);
printf("pArray size:\t%d\tarray size:\t%d\n", n, m);
return 0;
}
In the code above, the result of the sizeof() operation for the pointer array, whose size was allocated using malloc(), is a value of 4, or the size of a single element. The sizeof() function, however, returns the correct value of 40 for the normal array.
I always hear "arrays are just pointers in C." If arrays and pointers are functionally identical, why does sizeof() not work with the pointer array?