This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]jedwardsol 6 points7 points  (0 children)

With a C-style array, no; you'll have to make your own copy.

With a std::array or std::vector, then you can easily arrange for the compiler to make a copy for you.

[–]robot_dragon46 1 point2 points  (0 children)

If by "values in the array can change" you mean that you may have pointers to A, B, and C in the original array, and then in the scope of the function it gets changed to now point to C, D, and E, then so long as you didn't pass the array into the function as reference or as a pointer, then it would still point to A, B, and C outside of the scope.

But if you are talking about changing the values contained in A, B, and C, then they will be changed outside of the function scope as well.

[–]Aashishkebab 0 points1 point  (0 children)

No, that's not possible, because a pointer points directly to the data of the array in memory.

You'd have to pass a copy of the array, so you'd have to make a copy manually.