I have a C-array like this:
double arr[] = { 0.0, 0.1, 0.2, 0.5, 0.1, 0.2, 0.3, 0.4, 0.2, 0.0, 0.1, 0.3 }; Is it safe to get the number of elements like this?
int numElements = sizeof(arr)/sizeof(arr[0]); Or is there a better way?
I don't know of any other way to do this, since you don't have a size.
It is reliable, yes.
sizeof(arr)/sizeof(arr[0])works/meaning