|
-
Sep 22nd, 2000, 05:59 AM
#1
Thread Starter
Member
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
Cease
This post has been brought to you with the help of:
-
Sep 22nd, 2000, 03:33 PM
#2
Monday Morning Lunatic
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);
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|