// Sharissa Sullivan //January 20 2023 // Chapter 9 Array Expander // C ++ #include using namespace std; // prototype arrayExpander int* arrayExpander(int[], int size); int main() { //create an array - orignial array int array[] = { 1,2,3, }; int size = 3; int* arrayPtr = arrayExpander(array, size); // Print out arrays for (int i = 0; i, size; i++) { cout << arrayPtr[i] << endl; } return 0; } // function to create new array int* arrayExpander(int[], int size) { // ponits to new array with * size X 2 , and copied vaules from 1st array with 0 for the values int *expanderArray = new int[size * 2]; // copy orginial array into the second array and doblue the size for (int i = 0; i < size * 2; i++) { if (i < size) { // copies the orignal array expanderArray[i] = array[i]; // LINE 35 } else { //populates the number 0, for the new vaules in exapnder array expanderArray[i] = 0; } } return expanderArray; } LINE 35 , I am getting an error, can you please run the code and tell me what is wrong
// Sharissa Sullivan
//January 20 2023
// Chapter 9 Array Expander
// C ++
#include <iostream>
using namespace std;
// prototype arrayExpander
int* arrayExpander(int[], int size);
int main()
{
//create an array - orignial array
int array[] = { 1,2,3, };
int size = 3;
int* arrayPtr = arrayExpander(array, size);
// Print out arrays
for (int i = 0; i, size; i++)
{
cout << arrayPtr[i] << endl;
}
return 0;
}
// function to create new array
int* arrayExpander(int[], int size)
{
// ponits to new array with * size X 2 , and copied vaules from 1st array with 0 for the values
int *expanderArray = new int[size * 2];
// copy orginial array into the second array and doblue the size
for (int i = 0; i < size * 2; i++)
{
if (i < size)
{
// copies the orignal array
expanderArray[i] = array[i]; // LINE 35
}
else
{
//populates the number 0, for the new vaules in exapnder array
expanderArray[i] = 0;
}
}
return expanderArray;
}
LINE 35 , I am getting an error, can you please run the code and tell me what is wrong
Step by step
Solved in 4 steps with 3 images
Sample Output should look like this
The given array contains:
1 2 3
The expanded array contains:
1 2 3 0 0 0
Can you review your code and make corrections ?