What is the difference between copy and deep_copy methods in e language?
When do i have to use deep_copy(), and when using copy() is good enough?
Thanks!
copy copies the scalar fields,and keep references to the sub structs. While deep copy recursively copies all sub structs.
To copy scalars use copy. - will refer to sub structs. To copy sub-structs use deep copy.
Copy() copies only the scalar values, struct pointers and references the same list. Deep_copy() will create new struct instances recursively and assign new list and create the list elements. If the list elements are structs, then these will also be new instances
The difference is that copy() is shallow means it copy values of scalars and pointers to lists or structures. Deep_copy() is stronger copy with attributes for control the copy() method like reference or creation of new list/struct. When you need shallow copy with no concern to deeper hierarchy use copy(). When we need to give attention to deeper hierarchy use deep_copy().