-
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
-
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:
Code:
int arr[5];
cout << arr[3];
// equals:
cout << *(arr + (sizeof(int)*3));
...so just use something like this:
Code:
int sum(int *piArr, int iCount) {
...
}
void func() {
int arr[5];
cout << sum(arr, 5);
}