How do you get the size of an array? This old fashioned method works.
1 2 3 4 5 6 7 |
|
But if you don’t declare the array properly then things go horribly wrong. Never declare arrays as pointers!
The following C++ template function is much nicer. It does not compile at all when the array is declared as a pointer.
1 2 3 4 5 6 7 8 9 10 11 |
|
The countof
function takes a reference to an array and returns
its size. It is a compile-time constant.