#include <iostream>
int* copy_array(const int* arr, std::size_t size) // const because we don't intend to modify the contents of arr
{
int* copy = new int[size];
for (std::size_t i=0; i<size; ++i)
copy[i] = arr[i];
return copy;
}
void print(const int* arr, std::size_t size)
{
for (std::size_t i=0; i<size; ++i)
std::cout << arr[i] << ' ' ;
std::cout << '\n' ;
}
int main()
{
const std::size_t size = 8 ;
int array1[size] = { 5, 12, -2, 8, 47, 12, 81, 0 };
int * array1_copy = copy_array(array1, size) ;
print(array1, size);
print(array1_copy, size);
delete [] array1_copy;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKaW50KiBjb3B5X2FycmF5KGNvbnN0IGludCogYXJyLCBzdGQ6OnNpemVfdCBzaXplKSAgLy8gY29uc3QgYmVjYXVzZSB3ZSBkb24ndCBpbnRlbmQgdG8gbW9kaWZ5IHRoZSBjb250ZW50cyBvZiBhcnIKewogICAgaW50KiBjb3B5ID0gbmV3IGludFtzaXplXTsKICAgIGZvciAoc3RkOjpzaXplX3QgaT0wOyBpPHNpemU7ICsraSkKICAgICAgICBjb3B5W2ldID0gYXJyW2ldOwoKICAgIHJldHVybiBjb3B5Owp9Cgp2b2lkIHByaW50KGNvbnN0IGludCogYXJyLCBzdGQ6OnNpemVfdCBzaXplKQp7CiAgICBmb3IgKHN0ZDo6c2l6ZV90IGk9MDsgaTxzaXplOyArK2kpCiAgICAgICAgc3RkOjpjb3V0IDw8IGFycltpXSA8PCAnICcgOwogICAgc3RkOjpjb3V0IDw8ICdcbicgOwp9CgppbnQgbWFpbigpCnsKICAgIGNvbnN0IHN0ZDo6c2l6ZV90IHNpemUgPSA4IDsKICAgIGludCBhcnJheTFbc2l6ZV0gPSB7IDUsIDEyLCAtMiwgOCwgNDcsIDEyLCA4MSwgMCB9OwoKICAgIGludCAqIGFycmF5MV9jb3B5ID0gY29weV9hcnJheShhcnJheTEsIHNpemUpIDsKCiAgICBwcmludChhcnJheTEsIHNpemUpOwogICAgcHJpbnQoYXJyYXkxX2NvcHksIHNpemUpOwoKICAgIGRlbGV0ZSBbXSBhcnJheTFfY29weTsKfQ==