Michael Sullivan wrote: > The thread on returning arrays from a function raises a question to my > mind. Is there a way to determine how many elements are in the array > without explicitly passing the number of elements to the function? I > believe that in Java this is possible, but is it in C++? This is not a > homework question; just idle curiousity... >
The only way would be to have a marker value in the final position of the array. This is how strlen() knows how long a character array is, although in that case it technically only knows how many characters are part of the string, not the full array size. FYI as others mentioned, you can store the length in a struct with the array. This is essentially how C++ containers such as std::vector work, although they have additional functions and metadata. -- John Gaughan http://www.jtgprogramming.org/
