Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Statement: Dynamic memory allocation/reallocation of an Integer array. D

ID: 3611732 • 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 anarray of integers.

2.     Take array size as input from userand allocate memory according to this size.

3.     Take values of array elements as aninput from user.

4.    Print all array values.

5.     In this step; double the previousarray size (taken in step 2) and reallocate memory for the arrayaccording to new array size. For example if user provided arraysize is 4; now it will become 8, i.e. allocate memory for arrayhaving size 8.

6.    Now again take values for second half ofthe array as an input from the user to fill the increased size ofan array.(You have already taken the values of first half of thearray elements in step 3, now take values for remaining elementsi.e. Second half).  

7.     Print all values of the array.

8.     Also confirm that first half valuesof array are same in both printout statements (step 3 and step7).

        

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 8

Explanation / Answer

Problem Statement: Dynamic memory allocation/reallocation of an Integer array. D

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote