Question

In: Computer Science

In programming, we are always assigning one variable to another. With the use of primitive data...

In programming, we are always assigning one variable to another. With the use of primitive data types that is not a problem. With classes, the program needs to know how to do the assignment. Explain the concepts of deep copy and member wise assignment.

No duplicate answers please. C++ language

Solutions

Expert Solution

Memberwise/Shallow Copy

The variables A and B refer to different areas of memory, when B is assigned to A the two variables refer to the same area of memory. Later modifications to the contents of either are instantly reflected in the contents of other, as they share contents. Example below:

Deep copy:

The variables A and B refer to different areas of memory, when B is assigned to A the values in the memory area which A points to are copied into the memory area to which B points. Later modifications to the contents of either remain unique to A or B; the contents are not shared.

In short, it depends on what points to what. In a shallow copy, object B points to object A's location in memory. In deep copy, all things in object A's memory location get copied to object B's memory location.


Related Solutions

Compare and contrast the representation and use of primitive data types and built-in data structures such...
Compare and contrast the representation and use of primitive data types and built-in data structures such as C-strings and string objects?
Explain the differences between primitive and reference data types. Define the scope of a variable (hint:...
Explain the differences between primitive and reference data types. Define the scope of a variable (hint: local and global variable) Why is initialization of variables required. Differentiate between static, instance and local variables. Differentiate between widening and narrowing casting in java. the following table shows data type, its size, default value and the range. Filling in the missing values. TYPE SIZE (IN BYTES) DEFAULT RANGE boolean 1 bit true, false Char 2 ‘\0000’ to ‘\ffff’ Byte 0 Short 0 -215...
In the R programming language, we would like to use the data set called iris to...
In the R programming language, we would like to use the data set called iris to build a simple linear regression model to predict Sepal.Length based on Petal.Length. Calculate the least squares regression line to predict Sepal.Length based on Petal.Length. Interpret the slope of the line in the context of the problem. Remember that both variables are measured in centimeters. Plot the regression line in a scatterplot of Sepal.Length vs. Petal.Length. Test H1: ??1 ≠ 0 at ?? = 0.05...
What is a dummy variable? If we use one on the right-hand side of the equation...
What is a dummy variable? If we use one on the right-hand side of the equation in a multivariate analysis, what are the implications for interpreting the constant?  What is multicollinearity? How do we know if we have it in our models? How do we correct for it if we do?  What is hetereskedasticity? Should we really be concerned about it? Why or why not?
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: -getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. -getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. -getRowTotal. This method should accept a two-dimensional array as...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data...
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: fillRandom. Accepts a reference to a two-dimensional array and fills it with random integers from 0 to 99 formatPrint. This method should accept a two-dimensional array and print it out row by row getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in...
A property of spherical wave fronts is: They interact with one another to always produce positive...
A property of spherical wave fronts is: They interact with one another to always produce positive amplitude reinforcement. They interact with one another to always produce negative amplitude cancellation. They propagate radially outward from a center source in concentric circles. They always travel at the speed of light.
Linear regression is used to predict the value of one variable from another variable. Since it...
Linear regression is used to predict the value of one variable from another variable. Since it is based on correlation, it cannot provide causation. In addition, the strength of the relationship between the two variables affects the ability to predict one variable from the other variable; that is, the stronger the relationship between the two variables, the better the ability to do prediction. What is one instance where you think linear regression would be useful to you in your workplace...
Linear Regression Linear regression is used to predict the value of one variable from another variable....
Linear Regression Linear regression is used to predict the value of one variable from another variable. Since it is based on correlation, it cannot provide causation. In addition, the strength of the relationship between the two variables affects the ability to predict one variable from the other variable; that is, the stronger the relationship between the two variables, the better the ability to do prediction. What is one instance where you think linear regression would be useful to you in...
The acid-test ratio is another important ratio we can examine, although it always does seek to...
The acid-test ratio is another important ratio we can examine, although it always does seek to measure liquidity within a business. Overall, why do you think liquidity is such an important area of consideration for a business?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT