I am trying to duplicate a copy of the array but the new copy needs to be in reverse order. My problem is my reverse function, I commented what the error is stating, what I don't understand is why it's stating that? If copy is a pointer variable? I'm still struggling with pointers, and I really just want some clarification on what I am doing wrong. I didn't make a reverse pointer variable yet, I was planning to do that once I figure out why I'm given this error.
Here's the function
int* reverse(int elements, int size)
{
int* copy = new int [size];
int k =0;
for(int j=size-1; j >=0;j--)
{
copy[k] = size[j]; // Error-> Subscripted value is not an array,pointer or vector
k++;
}
return copy;
}
Here's the entire code without the function,
#include <iostream>
int* allocation(int);
void output(int*, int);
int* reverse(int*, int);
int main()
{
int size;
std::cout << "Enter the size you want to allocate" << std::endl;
std::cin >> size;
int* array = allocation(size);
std::cout << "Displays the elements of the array";
output(array,size);
return 0;
}
void output(int* array, int size)
{
for(int k=0;k<size;k++)
{
std::cout << " " << array[k];
}
}
int* allocation(int elements)
{
int* ptr = new int[elements];
std::cout << "Enter the elements for size of array." << std::endl;
for(int i =0; i < elements; i++)
{
std:: cin >> ptr[i];
}
return ptr;
}