When you declared n size was equal to zero, so n has zero elements. c and c++ don't check array bounds, they only throw errors when the program tries to access illegal memory (memory outside the defined space for the program).
For this problem the number of inputs are undefined. There could be ten, there could be a million. The amount doesn't matter.
Input a number. If it's 42 stop. Otherwise, output the number. Repeat.