Returning the size of an array problem.
Posted: Tue Nov 09, 2010 4:35 pm
Ok, I'm having trouble understanding why I get this outcome..
My array...
My function to get an arrays number of elements... takes te total size of the arrays memory uses then divides it by one element in the array.
This function only returns one.
Now if I do this I get a return of 17 which is what i need.
My array...
Code: Select all
int desX[] = {2730,2730,2730,2721,2728,2727,2720,2725,2728,2734,2730,2728,2730,2741,2738,2738,2732};
This function only returns one.
Code: Select all
//Declaration is like this...
int length(int array[]);
//function call from my main is...just to test it.
cout<< length(desX);
//Get array length
int length(int array[])
{
return (sizeof(array) / sizeof(array[0]));
}
Code: Select all
cout<< sizeof(desX) / sizeof(desX[0]);