Suppose you declare a static array of integers, say, int arr = [5]. (10 points)
ID: 3904216 • Letter: S
Question
Suppose you declare a static array of integers, say, int arr = [5]. (10 points)
You initialize its values. Then, you declare two more arrays:
one that is also static, called sArr, and another dynamic, called dArr.
a. Explain the process of initializing dArr by shallow-copying arr.
b. Explain the process of initializing sArr by deep-copying arr.
c. Explain what methods you use (loops, temporary variables, pointer arithmetic, etc.)
d. Now, suppose you change one or more of the elements in dArr.
What will happen to the corresponding elements in sArr?
What about in arr?
Explanation / Answer
a. Explain the process of initializing dArr by shallow-copying arr. Answer: -------- int *dArr = arr; b. Explain the process of initializing sArr by deep-copying arr. Answer: -------- int *dArr = new int[arr.length]; for(int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.