I thought that the above program would crash as the local objects are not stored in the heap. I can actually see the output of the program as 10 at line 1 and it seems to have worked correctly. Can someone please explain?
Sometimes undefined behavior will mean it crashes... other times it means it will make your program act very strangely... and other times it will mean it proceeds as if nothing out of the ordinary had happened. There's no way to know what's going to happen because it's undefined.