Hello, I am running into trouble with (what I thought would be) a simple algorithm that takes in an int array, and returns the number of elements in the array. It seems to work with arrays with only one digit, but does not work with arrays with int values >9 or <-9 . I was under the impression that pointer arithmetic takes into account the size of the elements in the array, but no matter what changes I make, arrays with multiple digit values always seems to run off the array with this function. Does anyone have any ideas on what I might be doing wrong?
int Alg::getSize(int array[])
{
int size = 0;
int* ptr = &array[0];
while ((*ptr) != '\0')
{
size++;
ptr++;
}
return size;
}