The assignment: Write a function that accepts an int array and the array s size
ID: 3538943 • Letter: T
Question
The assignment: Write a function that accepts an int array and the array s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. The function should return a pointer to the new array. 9.12 in Gaddis C++ From control structures through objects use correct loop iteration condition. must account for a memory leak as well.Explanation / Answer
int [] createArray(int arr[], int size)
{
int *nArr = new int [size+1];
nArr[0] = 0;
for(int i=0;i<size;i++)
nArr[i+1] = arr[i];
return nArr;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.