I have two pointers which point to unsigned char array. I want to add the second unsigned char array after the first unsigned char array and return me a new pointer. Can someone share the correct and concise way to do this, thanks!
Asked
Active
Viewed 33 times
0
-
3Assuming you are talking about a dynamic allocated array with new [] You have to allocate a new larger array and copy both to the new location. If you are doing this you probably want to switch to use std::vector instead. – drescherjm Apr 05 '22 at 14:55
-
Please take some time to refresh [the help pages](http://stackoverflow.com/help), especially ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also take the [tour] and read about [ask] good questions and [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly don't forget how to create a [mre] of your own attempt. – Some programmer dude Apr 05 '22 at 14:55
-
1Functions that return "a new pointer" are relatively uncommon in C++ because one must also consider the lifetime of that memory being pointed to. Should the memory hold this result forever? Should the caller remember to `delete[]` the memory when it is no longer needed? Should the function return a `std::vector` or `std::unique_ptr` instead of a raw pointer, so the memory will be managed automatically? – Drew Dormann Apr 05 '22 at 15:06