dynamic array problem: making two dynamic arrays and copying one in another...

Write a program that takes integer input from the user and store into the array dynamically allocated each time a new element is added. Your program should prompt user to take integers until he enters -1, which means end of input. After taking all the numbers print them in the reverse order as entered by the user.

the code which i have written is attached along.
it is printing junk values.
need help :)

The code continually allocates new memory to ptr, which leaks away the previous memory and loses any previously assigned numbers. Rather than outline all of the possible cases and explain why they're necessary, I'll just give you a function to study:

Since this new ptr variable is declared inside your loop, it is destroyed at the end of your loop, and the new int[] memory which you'd allocated is being leaked, since there are no other references to it in your program.

I'd suggest renaming one of your 'ptr' variables, and being careful to ensure that the memory you're allocating is properly tracked, and also deleted when you no longer needed. (Note, memory allocated using new[] needs to be cleaned up with delete[] - don't omit the subscript [] operator)

Alternatively, a smarter way to do this (without new/delete) would be to avoid yucky stuff like pointers and new/delete, then to replace it with a vector (which is a resizable "C++ array")

Write a program that takes integer input from the user and store into the array dynamically allocated each time a new element is added.

Note the wording: "store into the array dynamically allocated ".
Allocate a buffer of sufficient size -- once.
There is nothing in the instructions that says allocate a new buffer for each and every integer.