-
Pointers?!
I have a function inside an object that I want to pass in an array to. I then want to modify it and pass it back. I assume the only way to do this is to use pointers to an array.
How do i reference every position in the array and how do I pass it in and back?
Thanks
Rich
-
Arrays are passed to functions as pointers to the first element. This is the default behavior in C++, so you can simply do something like this:
Code:
void object::function ( T array[], int size );
Because the array is really a pointer, you have no way of calculating its size without help. So it's usually a good idea to pass the size of an array along with the array itself. Now you can modify the array however you want and the changes will persist back to the caller.