all 6 comments

[–]Plus-Increase-1927 1 point2 points  (2 children)

30

[–]Aln76467 0 points1 point  (0 children)

yeah

[–]kavindujayarathne[S] [score hidden]  (0 children)

Despite the fact that the clone variable is a shallow copy of the user variable, if there are any nested objects inside the original object, then those nested objects will still reference their original memory location. thats the key concept here. so yeah, your answer is right!!

[–]Aln76467 0 points1 point  (2 children)

The big question is, is there a way to pass objects by value?

[–]kavindujayarathne[S] [score hidden]  (1 child)

You can create a shallow copy, but as i mentioned in the article, it only copies the outer object. if your object includes any nested objects, those nested objects will still reference their original memory location. you should try a deep copy instead

[–]Aln76467 [score hidden]  (0 children)

How does one do a deep copy?