If I do the following:
string* create_array(){
string* arr = new string[2];
string s = "hello";
string s2 = "world";
arr[0] = s;
arr[1] = s2;
return arr;
}
is the assignment of arr[0] = s making a copy of s and then putting that copy in the memory address that arr[0] points to? or is it making arr[0] refer to the local stack variable s, and in this case if I use the array returned from this function calling arr[0] will have unpredictable behaviour?
Thanks
newfrom a function. Consider usingstd::vectororstd::arrayinstead. You usually should not mess with raw pointers when you don't sure you need to, or, especially, if you doubt in how they work.std::arrayshould actually be faster.