1234567891011121314
#include <iostream> template <typename T, size_t N> size_t array_size(T (&)[N]) { return N; } int main() { //Usage const char *a[]={"abc","def","ghi"}; std::cout << array_size(a); }
3
12345678910111213
#include <iostream> size_t array_size(const char* c[]) { return sizeof(c)/sizeof(c[0]); } int main() { //Usage const char *a[]={"abc","def","ghi"}; std::cout << array_size(a); }
1