>what exactly is segmentation fault or access violation and exactly when does it occur?
A segmentation fault is when you access memory outside of your address space and the OS politely asks you not to do that.
>Why does the following program work correctly
Undefined behavior can do anything, including work the way you expect it to. Don't rely on a single implementation to tell you what works and what doesn't. We have a standard document for that.
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Offline 11,807 posts
since Sep 2004