hi, i am trying to write some code that passes argv[1] into a function, i know the code part works in main on its own, but im having an issue with how to pass argv[1] to a function. any help would be greatly appreciated.... ty.
Disregard that. Arrays in C++ are pointers to the beginning of memory area containing array data. You can dynamically allocate memory for you array (so it won't deallocates when function returns) and return a pointer to it.
1. That's incredibly slow.
2. It's unsafe without very strict overview of code.
3. You have no idea the size of the array unless it's hard coded, which in this case, it is not. You could set a global except this would ruin any type of re-entrancy rules and there are obviously better methods to go about this (such as passing the array as a parameter).
You might also be able to use std::array but I'm not sure if it uses an allocator or not, or how it handles copying.
1. That's incredibly slow.
Why?
Arrays are passed by reference. A pointer is a 4-byte integer. Do you mean the code itself?
@jonnyprogrammer
If your compiler supports C++11, use uniqe_ptr, if you want to return a dynamically allocated memory. It will deallocate it at the end of the main function. If does not support, vector is good enough for that.
Its slow because you make an unneeded allocation on heap.
You continue to propose methods that are looked down upon due to their proneness for error and fundamental issues such as performance.