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?
This is the best way. Even it is suggested in C programming book by Dennis ritchie.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With