I'm new to c programming. I want to create a function that takes an integer array as argument and returns length of the array. I know that the code below calculates the length correctly.
int arr[] = {1, 2, 3, 4, 5};
int length = sizeof(arr) / sizeof(arr[0]);
But if I create a function like below and pass the array as an argument, it doesn't work.
int length_of(int* arr) {
return sizeof(arr) / sizeof(arr[0]);
}
My guess is that I'm not passing the array into the function correctly. What is the correct way of implementing this?