Function return int [] (using pointer)

Hi, everyone, im learning c++ and and I did the following problem, i need a function that return an array int[], know that its not possible without pointer :

int* returnarray(int[] array1){ // suppose int array1[4]={1,2,3,4}
int aux[4];
int *pAux;
return pAux;

int main(int argc, char *argv[]) {
int Myarray[4]={1,2,3,4};
int *pNewArray=returnarray(Myarray);
int NewArray[4];
// and now the problem how assign values of pointer *pNewArray to NewArray
// I tried
//and next...
//another form???
return 0;

for(int n = 0; n < 4; ++n)
    NewArray[n] = pNewArray[n];
Function returnarray() is attempting to return a pointer to a local object. When the function has returned, the local object no longer exists, the memory where it previously resided may be reused for other purposes.

Either return a pointer to the original array (input parameter of the function) or allocate a fresh array using new.
Topic archived. No new replies allowed.