Hello!
Recently, I learn C language, I have a problem. The example as follow:
int numOfArray(int num[]);
int main()
{
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
printf("the number of array is: %d.\n", sizeof(a)/sizeof(a[0]));
printf("\n");
printf("after calling function.\n");
printf("the number of array is: %d.\n", numOfArray(a));
return 0;
}
int numOfArray(int num[])
{
return sizeof(num)/sizeof(num[0]);
}
The result is: the number of array is:9.
after calling function.
the number of array is:1.
As we know, array is transmitted in function through address. Why the two results are different? I hope someone can help me. Thanks.