45
I've seen several macros for array length floating around:
From this question:
#define length(array) (sizeof(array)/sizeof(*(array)))#define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0]))#define SIZE(array, type) (sizeof(array) / (sizeof(type))
And Visual Studio's _countof:
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
What I'd like to know is:
- What's the difference between those using
array[0]and*array? - Why should either be preferred?
- Do they differ in C++?