Shallow vs Deep Copy (with examples)
- A shallow copy shares its children with the original
- A deep copy has its own copies of the children
The above example showed an object graph. Same story for arrays.
If there are no children?
Since the concept of deep vs shallow concerns treatment of children, it’s meaningless to talk about deep vs shallow copying of objects (or arrays) that doesn’t have any children.
pointerA = pointerB?
When you do
pointerA = pointerB you’re just copying a pointer value, so no object is copied. Neither deep nor shallow. You could say that it’s a shallow copy of the pointer value, since the object it points at is not copied.