How come this code executes?
Because the behaviour of the program is undefined.
There is no guarantee that the program will crash, nor is there a guarantee that it won't crash. There are no guarantees about the behaviour whatsoever.
I expected output to be crash
You cannot rely on the program to behave the way you expect when the behaviour is undefined.
int* t= new int(10); t[1] = 1000; never works. Here I also expect
How do you know that it "never works"? Have you observed every execution of every program where that has been written, compiled with every version of every compiler both past and future, with and without all of the various options that the compilers have to offer, on every system in existence? I suspect that you haven't. Even if we were to assume that you have, there still would be no guarantee that it behave in the way you expect.
This program "never works" in the same sense that the program in the question "never works". The behaviour is undefined and anything might happen. It might:
- Always crash
- Never crash
- Sometimes crash
- Crash when you run it, but not when someone else does
- Always have specific output
- Never have that output
- Sometimes have that output
- Always have no output
- Never have any output
- ...
This list is infinite.
I think even UB in most cases have some explanation, like in my case why it's not crashing
There is no answer to that within C++. You must instead read the assembly language program generated by the compiler and ask "why does this assembly program crash", then answer may be found in the manuals for your CPU and operating system.