February 4th, 2009, 06:50 PM
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;
while ((*ptr) != '\0')
Last edited by Rahl; February 4th, 2009 at 06:54 PM.
Tags for this Thread
Click Here to Expand Forum to Full Width