Your reply still has some holes that need to be filled |
-- Let's see if I can fill the holes.
Ganado has pointed out one of the key reasons that the function doesn't work, it's called 'scope' if you want a term you can search. One way around scope issues is to utilize dynamic memory, which is how a vector works (and how several C++ container classes like vector work). Key words to look up when studying dynamic memory are 'new' 'delete' 'heap' 'stack' 'vector' 'linked list' 'list' 'memory leak', 'dangling pointer'.
Once you have created a dynamically allocated array of integers, you could return a pointer to that data. That pointer can be treated as if it were the original array. Which is where pointers start to become a very light-weight tool for very powerful operations.
There is one more way to get around your scope issue, and that's to take an array or a pointer to an array as the function's argument, then just modify that existing array. No return statement would be necessary at that point.
Jonin points out another issue which C++ inherits from C, which your link to stackoverflow describes. An array can't be initialized by another array. C++ introduced classes and operator overloading and many advanced ideas, but before that it was hard to say how assignment should work on all blocks of data, so sadly they chose to avoid it completely for arrays in the original C language.
If you look at the source behind the std::copy function, it basically is going to be a loop that does what jonnin suggests. (Though they may use assembly to tap into larger data sizes such as SIMD AVX-512, this is unlikely, advantages of doing so are hindered by the ram speed bottleneck) Many times advanced coders are going to edge towards creating code that is easier to maintain rather than getting too fancy.
Ganado, Jonnin, and I all recommend you check out vectors (and other container classes), which solve the assignment operator problem. Take a day and research vectors, it sounds like you might be ready to step beyond C language ideas and into the things that C++ has to offer.
http://www32.cplusplus.com/reference/vector/