PDA

Click to See Complete Forum and Search --> : Number in an array


Cease
Sep 22nd, 2000, 05:59 AM
Okay i need a bit of help here, i am going to be passing a number of intagers to a function which will add them all up and return the sum, but i need to know how many intagers are in the array, can someone please help me with this?
I would preferabally like to do it without sending the number of intagers in thar array to the function?
Thanx
Cease

parksie
Sep 22nd, 2000, 03:33 PM
You can't. It's the nature of C++ that an array is merely a pointer to a memory location, at which you own xxx bytes. Therefore, when you use an array index, it's like this:

int arr[5];

cout << arr[3];
// equals:
cout << *(arr + (sizeof(int)*3));

...so just use something like this:

int sum(int *piArr, int iCount) {
...
}

void func() {
int arr[5];
cout << sum(arr, 5);
}