There is no ‘built-in’ way to determine the length inside the function. However you pass arr
, sizeof(arr)
will always return the pointer size. So the best way is to pass the number of elements as a seperate argument. Alternatively you could have a special value like 0
or -1
that indicates the end (like it is \0
in strings, which are just char []
).
But then of course the ‘logical’ array size was sizeof(arr)/sizeof(int) - 1