> Despite not giving enough space to x this code is giving output as "hello world". Why?
Because of pure dumb luck.

I would suggest you learn how to do it properly, instead of experimenting with all sorts of undefined behaviour and wondering why various things do (or do not) happen.