You have to pass the array by reference; you cannot pass arrays by value (they decay into pointers to the first element):
int myFunc(char const (& my_array)[5])
{
return sizeof(my_array); // or just "return 5"
}
In case that you want to call this function with a reference to lots of different local arrays, you can use a function template instead to have the array size deduced:
template <unsigned int N>
int myFunc(char const (& my_array)[N])
{
return sizeof(N); // or "return N"
}
You should really make the functions return an unsigned int
or an std::size_t
, though. In C++11, you can also declare them as constexpr
.