On Thu, 2009-04-02 at 11:00 -0400, Jim Dougherty wrote: > > > > > > ----- Original Message ----- > > From: Michael Sullivan > > To: [email protected] <mailto:c-prog%40yahoogroups.com> > > Sent: Thursday, April 02, 2009 8:49 AM > > Subject: [c-prog] How many elements in the array? > > > > 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... > > > > [email protected] wrote: > > > > sizeof(array)/sizeof(array_type) > > > > Thanks, > > Tyler Littlefield > > I think that the question was asking if the called function could > determine the size of the array, not the calling function. I think > that > the answer is that the called function cannot determine the size of > the > array by itself, the size needs to be passed in.
Still, the called function would have a pointer to the passed-in array and would know its type, so couldn't it still do the sizeof thing?
