+ 1
Easier to bring in pointers and arrays to explain this: where arr is {1,2,3} Shallow: Int* copy = arr; copy points to the address of what you're copying, in this case the address of arr. When you delete the array, what will copy be pointing to then? Trash. Unknown. Deep Copy: int* copy= new int[3]; // Then for loop copy[i] =arr[i]; copy copies all values of arr so that when you delete or change arr, copy still points to the new allocated memory int[3] with copied values 1 2 3 The difference lies in that deep copy makes copy independent. Do whatever you want to arr, copy will not change after the deep copying (1 2 3)
1st Dec 2017, 12:17 AM
Echo One
Echo One - avatar