newarray
is an automatic local variable. It will no longer exists once function return. Returning pointer to an automatic local variable invoke undefined behaviour and in this case nothing good can be expected.
You can allocate memory diynamically and then return pointer to it
int *newArray = malloc(sizeof(int)*size);
2
solved Returning pointer to array doesn’t give expected output in c [duplicate]