It's not working fine. You're corrupting the heap. You're writing to some arbitrary memory location that you shouldn't be.
The fact that it appears to work is exactly why heap corruption is so dangerous. Sometimes it's no problem, until 3 months later when you make some other unrelated change. Then when you try to run your program it explodes and the bug is incredibly hard to track down and fix.
It's a general fact (as in, pertains to a compiler that follows C++ standard. Code::Blocks is not a compiler but one can assume you are using MinGW with Code::Blocks). Please be sure and read what Disch said thoroughly. Here's a few corrected versions of your code for example:
1 2 3 4
int i;
int *p = &i;
*p = 5;
//Be careful though, once the current scope for i is up, p points to an undetermined location.
Really, a common C++ developer doesn't need to know how new, delete, and stack work as long as they know they syntax to them and what they're used for. However, I find the more I know about how something works, the better I can understand my own code.