Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is what I have so far but I have come across multiple errors. I think i need to dynamically allocate the new array. Please
This is what I have so far but I have come across multiple errors. I think i need to dynamically allocate the new array. Please provide comments throughout the program(This is why I did this etc)
C++ Programming
Here is what I have so far
#include
#include
using namespace std;
int* getArray(int array, int ARRAY_SIZE)
//The size of the array and array placeholder
{
int num[ARRAY_SIZE]; //The combination of numbers and arrau
int a, b = 0; //A and B used as the separate array integers
for (a = 0; a
Reverse Array Write a function that accepts an int array and the array's size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function in a complete program {
num[a] = array[a]; //Copying the array A with a different array
}
for (a = array_size - 1; a >= 0; a--)
{
array[b++] = num[a]; //Having b=a in transfer
}
return array; //Pointer to store the array itself
}
int main() //Start of Program
{
const int SIZE = 6;
int nums[SIZE] = { 3, 4, -7, 6, 9, -2 };
int* numArr = nums;
//int* num; //Call the getArray function to get pointer
num = getArray(*nums, SIZE);
printf("Array outside function in reverse form "); //Printf is formatting the function
for (int a = 0; a
{
printf("%d\t", num[a]); //Helps with the spacing
}
return 0; //End of program
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started