Within the main method this is easy as I simply use:
Expand|Select|Wrap|Line Numbers
- sizeof( <array name> ) / sizeof( <array type> )
my function reads:
Expand|Select|Wrap|Line Numbers
- int numElements( int array[] ){
- int sizeOfArray = sizeof( array ) / sizeof( int );
- return sizeOfArray;
- }
Expand|Select|Wrap|Line Numbers
- int intArray[50];
- cout << numElements( intArray );
I am guessing this has something to do with the fact that an array name is really just a pointer to the first element in the array, and as a result the function is only seeing the first element (and therefore is returning 1)... but is there anyway to get the function to see the whole array?
I realize I could probably save myself the headache if I just used vectors... but I kind of wanted to see if I could get this to work with arrays.
So really all I want to do is condense
Expand|Select|Wrap|Line Numbers
- sizeof( <array name> ) / sizeof( <array type> )
Thanks for any help!