amiable, what exactly is it you want us to tell you?
We've told you what is wrong. Using an uninitialized pointer is illegal. When a pointer is dereferenced, it should only ever be pointing to vaild data that your program itself has made.
Just because this particular case happens to work with your particular compiler+OS doesn't mean it will work with another person's computer. Even if you get the same address every time you run it.
When coding in C++, you have to be aware of what can cause undefined behavior. If this is too annoying, note languages like C# (well, most of it) and Java don't allow for undefined behavior.
PS: The code you posted here
(
http://www.cplusplus.com/forum/beginner/240320/#msg1070108 )
does not even compile (bad syntax). So I can't even tell you what happens, because that is clearly not your actual code...
MikeyBoy wrote: |
---|
The only people who know, are the people who wrote gcc. |
They'll probably just be able to guess a
little bit better than we can as to what choices the compiler is making. ;)