I have a C++ array declared as mentioned below:
CString carray[] = { \"A\", \"B\", \"C\", \"D\", \"E\" }
That's not runtime, it's compile time. The way you're using is correct. Note that Visual Studio defines a _countof function that does the same.
_countof
At runtime, the length cannot be determined. You either keep a length yourself, or use std::vector
std::vector