i would like to find the size of integer array passed as an argument to a function. Here is my code
void getArraySize(int arr[]){
int len = (sizeof(arr)/sizeof(arr[0])
printf("Array Length:%d\n",len);
}
int main(){
int array[] = {1,2,3,4,5};
getArraySize(array);
return 0;
}
I am getting the following warning
sizeof on array function parameter will return
size of 'int *' instead of 'int []' [-Wsizeof-array-argument]
Please help so that i can find the length of integer array inside the function
getArraySize
However am able to find the size of the array
inside the main
function.Since it is passed as a pointer
, am not able to find the length
from with in the function
.
i do have an idea though.I could put this with in a try/catch
block(C
does not have try catch,Only jumpers which is OS dependent) and loop until i get a segmentation fault
.
Is there any other way i could use to find the length of integer array
inside the function