What is the difference between a deep copy and a shallow copy?

Source: Internet
Author: User
Tags shallow copy

A shallow copy is a source object that is shared with a copy object, and only refers to a variable (with a different name). A shallow copy is a pointer copy, and a change to any of these objects affects another object.

For example, a person at the beginning of the call Zhang San, later renamed John Doe, but still the same person, whether it is Zhang three missing arms or legs or Li four short legs, is this person unlucky.

deep copy means that the source object and the Copy object are independent of each other, and the deep copy copies the contents of the pointer to the pointer copy, and no change of any object will affect the other object.

For example, a person named Zhang San, later with his cloning (assuming the law allows) another person, called John Doe, whether it is Zhang three short arms or legs or Li four lack of arms and legs will not affect another person. A typical value object, such as a predefined type Int32,Double, and struct (struct), enumeration (enum), andso on.

What is the difference between a deep copy and a shallow copy?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.