I defined the following function to find the length of an integer array:
int loa(int arr[]){
int size = sizeof(*arr)/sizeof(arr[0]);
return size;
}
However, when I do the following:
int main(){
int arr[3] = {1, 2, 3};
printf("length of arr is %lu\n", sizeof(arr)/sizeof(arr[0]));
printf("length of arr is %d", loa(arr));
return 0;
}
The output is:
length of arr is 3
length of arr is 1
I don't understand this behavior. What am I doing wrong here?