When x=10 and y=x,which of the following memory assignment is correct answer is
Answers
Answered by
0
Answer:
X and Y will have two distinct location and 10 will be saved in both
Explanation:
- At first line that is X=10, the value of 10 is stored in X. So, the first designation of the value of 10 is done to X.
- Whereas the in the next syntax the value of X is said to be Y, meaning the everything that is designated to X is now transferred to the variable Y.
- Making the new variable that contains 10 is Y but 10 has not vacated its previous address it just has duplicated itself now both X and Y contains the same value but in different location.
Answered by
0
X and Y will have different memory location with same value 10.
There are two types of copy.
1. Shallow copy 2 Deep Copy
Shallow copy: Copies only values but does not share or point to same memory location
Deep copy: Copies values as well as share memory location. If the value of one variable changes it changes the other also.
The given statement, y = x belongs to shallow copy, because only the value of x is copied to y and it does not share address. If these both are pointer variable then address can be assigned and shared and thus perform a deep copy.
Similar questions