This line is root of problem:
short int newarray[size];
It allocates array in stack, and then you return address of that, even though it becomes invalid as soon as you return from that function. Try this:
short *newarray = new short [size];
Now it goes to heap. Of course you should also delete that with delete[] operator when you no longer need it, like maybe in main after printing:
delete[] nptr;