How do I reliably get the size of a C-style array? The method often recommended seems to be to use sizeof, but it doesn\'t work in the foo function
sizeof
foo
Since c++11, there is a very convenient way:
static const int array[] = { 1, 2, 3, 6 }; int size = (int)std::distance(std::begin(array), std::end(array))+1;