Problem Statement: Dynamic memory allocation/reallocation of an Integer array. D
ID: 3611692 • Letter: P
Question
Problem Statement:
Dynamic memory allocation/reallocation of an Integer array.
Detailed Description:
Write a program in which you have to:
1. Dynamically allocate an array of integers.
2. Take array size as input from user and allocate memory according tothis size.
3. Take values of array elements as an input from user.
4. Print all array values.
5. Inthis step; double the previous array size (taken in step 2) andreallocate memory for the array according to new array size. Forexample if user provided array size is 4; now it will become 8,i.e. allocate memory for array having size 8.
6. Nowagain take values for second half of the array as an input from theuser to fill the increased size of an array.(You have already takenthe values of first half of the array elements in step 3, now takevalues for remaining elements i.e. Second half).
7. Print all values of the array.
8. Also confirm that first half values ofarray 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 78
______________ help mefriends_____________
Problem Statement:
Dynamic memory allocation/reallocation of an Integer array.
Detailed Description:
Write a program in which you have to:
1. Dynamically allocate an array of integers.
2. Take array size as input from user and allocate memory according tothis size.
3. Take values of array elements as an input from user.
4. Print all array values.
5. Inthis step; double the previous array size (taken in step 2) andreallocate memory for the array according to new array size. Forexample if user provided array size is 4; now it will become 8,i.e. allocate memory for array having size 8.
6. Nowagain take values for second half of the array as an input from theuser to fill the increased size of an array.(You have already takenthe values of first half of the array elements in step 3, now takevalues for remaining elements i.e. Second half).
7. Print all values of the array.
8. Also confirm that first half values ofarray 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 78
______________ help mefriends_____________
Explanation / Answer
Problem Statement: Dynamic memory allocation/reallocation of an Integer array. D
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.