S
sugaray
Hi, my problem with calculating the size of an array is when
I pass an array as a parameter to a function which perform the
calculation, the result never comes right, like below:
int SizeOfArray(int a[]) {
return (sizeof(a)/sizeof(a[0]));
}
main() {
int a[3]={1,2,3};
printf("%d\n",SizeOfArray(a));
}
but is right when the array declared in the same scope as the sizeof()
statment,
main() {
int a[3]={1,2,3};
printf("%d\n",sizeof(a)/sizeof(a[0]));
}
why's that ? i suspect that i passed the wrong type of parameter to
the function. (should be &a or *a or something... ??)
I pass an array as a parameter to a function which perform the
calculation, the result never comes right, like below:
int SizeOfArray(int a[]) {
return (sizeof(a)/sizeof(a[0]));
}
main() {
int a[3]={1,2,3};
printf("%d\n",SizeOfArray(a));
}
but is right when the array declared in the same scope as the sizeof()
statment,
main() {
int a[3]={1,2,3};
printf("%d\n",sizeof(a)/sizeof(a[0]));
}
why's that ? i suspect that i passed the wrong type of parameter to
the function. (should be &a or *a or something... ??)