The while
loop never terminates:
First iteration:
*p = 10, out = 11
Next iteration:
*p = 20, out = 21
Next iteration:
*p = 30, out = 31
Next iteration:
*p = 0, out = 1
Next iteration:
You are accessing unauthorized memory, which leads to undefined behavior.
Update
After the last item from the array is accessed, the part of the stack frame that contains code gets trampled over by the increment operator. Hence, the code cannot be expected to behave in a logical manner.