Please explain the difference between shallow copy and deep copy?
Submitted by: AdministratorShallow copy is also known as address copy. In this process you only copy address not actual data while in deep copy you copy data.
Suppose there are two objects A and B. A is pointing to a different array while B is pointing to different array. Now what I will do is following to do shallow copy. Char *A = {'a','b','c'}; Char *B = {'x','y','z'}; B = A; Now B is pointing is at same location where A pointer is pointing.Both A and B in this case sharing same data. if change is made both will get altered value of data.Advantage is that coping process is very fast and is independent of size of array.
while in deep copy data is also copied. This process is slow but Both A and B have their own copies and changes made to any copy, other will copy will not be affected.
Submitted by:
Suppose there are two objects A and B. A is pointing to a different array while B is pointing to different array. Now what I will do is following to do shallow copy. Char *A = {'a','b','c'}; Char *B = {'x','y','z'}; B = A; Now B is pointing is at same location where A pointer is pointing.Both A and B in this case sharing same data. if change is made both will get altered value of data.Advantage is that coping process is very fast and is independent of size of array.
while in deep copy data is also copied. This process is slow but Both A and B have their own copies and changes made to any copy, other will copy will not be affected.
Submitted by:
Read Online Apple Job Interview Questions And Answers
Top Apple Questions
☺ | Explain popular apps of iPhone? |
☺ | Explain iphone architecture? |
☺ | How to parse a phone number from a huge database of a n billion webpages in 30 minutes |
☺ | Design a chess game. Basics of a chess game was explained and a player could be human or AI? |
☺ | Please explain the difference between shallow copy and deep copy? |
Top Companies Job Categories
☺ | TCS Interview Questions. |
☺ | Infosys Interview Questions. |
☺ | IBM Interview Questions. |
☺ | Wipro Interview Questions. |
☺ | Google Interview Questions. |