I wrote an array_length function like this:
int array_length(int a[]){
return sizeof(a)/sizeof(int);
}
However it is returning 2 when I did
unsigned int len = array_length(arr);
printf ("%i" , len);
where I have
int arr[] = {3,4,5,6,1,7,2};
int * parr = arr;
But when I just do
int k = sizeof(arr)/sizeof(int);
printf("%i", k);
in the main function, it returns 7.
What is the correct way to write the array_length function and how do I use it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…