array problem

how do i pass a loaded array from a function back to my code?
Check the tutorial, arrays section. http://www.cplusplus.com/doc/tutorial/arrays/
Last edited on
i want to return the array from the function into another array in the body of the code but the tutorial doesnt really say how to do that
Arrays are treated as pointers, so you could theoretically return the array from a function of return type sometype* or sometype&. However, if you generated the array in the function, that will return an invalid value (because the data at that address would be destroyed when the function ended).
I really despise passing around arrays. It's so messy. I much prefer working with STL containers (vector is much easier to work with).
This kind of question is one of the reasons that I wrote this. It is a starting point at the very least which might give you some ideas how to do it and how not to do it.
http://cplusplus.com/forum/articles/20881/

Keep in mind that I tend to agree with Tummychow which is why I focused heavily on using the template sequence containers instead of C-Arrays. It sounds like the calling function creates an array and sends it to a function to be filled. In that case the article that I wrote shows a couple of different ways of doing this by passing the pointer to the array as an out parameter to a function.

Since the term array can mean many things depending on the context of the sentence I use the term C-Array to describe something like this
int ValueArray[25] = { 0 };

The term array could mean any kind of sequence container with random access if you are speaking in a more general sense. Since you didn't post an example I do not know if you are required to use C-Arrays or if you can use the sequence containers of the STL.
Topic archived. No new replies allowed.