fork download
  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. template <typename T, size_t N>
  6. size_t len(T (*)[N]) {
  7. return N;
  8. }
  9.  
  10. int main() {
  11. int foo[10];
  12. cout << len(&foo) << endl;
  13.  
  14. const size_t n = 42;
  15. double baz[n];
  16. cout << len(&baz) << endl;
  17.  
  18. cout << len(&"hello") << endl;
  19. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
10
42
6