Dynamic memory allocation/reallocation of an Integer array. Det a iled Des or ip
ID: 3611654 • Letter: D
Question
Dynamic memory allocation/reallocation of an Integer array. Det a iled Des or ipt ion : Write a program in which you have to: Dynamically allocate an array of integers. Take array size as input from user and allocate memory according to this size. Take values of array elements as an input from user. Print all array values. In this step; double the previous array size (taken in step 2) and reallocate memory for the array according to new array size. For example if user provided array size is 4; now it will become 8, i.e. allocate memory for array having size 8. Now again take values for second half of the array as an input from the user to fill the increased size of an array.(You have already taken the values of first half of the array elements in step 3, now take values for remaining elements i.e. Second half). Print all values of the array. Also confirm that first half values of array are same in both printout statements (step 3 and step 7). Sample Output Program to dynamically Allocates an array of integers. Enter the size of the array: 4 Enter a value: 1 Enter a value: 2 Enter a value: 3 Enter a value: 4 The elements of the array are: 1 2 3 4 Enter the elements in the array after reallocation: Enter a value: 5 Enter a value: 6 Enter a value: 7 Enter a value: 8 1 2 3 4 5 6 7 8Explanation / Answer
Your question is a dupe of ghulam 007's post "cprogramming"... Check out my answer there.
Cheers, niels
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.