They don't. They just get whatever left-over memory was there. If you run your tests enough they'll be different each time, or the same, it is not guaranteed.
I've been teaching programming for 30 years now (C++ for the last 12) and these values are consistent for me and every one of the students in the lab. I understand the concept of leftover garbage, it just seems like it gets consistently translated to these values.
It's not guaranteed. My closest guess is that whatever initialization happened before main was called left those values in the memory every time for the implementation you use. For me in VC++2008 its completely random every time I run it, Debug or Release alike, but other compilers may be different.
It's hex 0xCCCC... Some compiler fill the memory in the debug version with values like that. So that the programmer can recognize not initialzed memory easier
Perhaps Moschops last answer is a little more logical than his previous ones
It's the exact same answer. If you consistently run in MS debug mode, it will consistently dump the same values into memory to mark it as uninitialised.
Perhaps you should know your tools better than you do.
Your question was "in a C++ console application", in which case the result is undefined (random). On MVC++, two specific values are used to signify uninitialized stack and heap variables.
I'm shocked that you've been teaching for 30 years without knowing this.
@ Gaminic. I'm equally shocked thatyou define a repeating result as being RANDOM?
@Moschops. I'm quite satisfied with my knowledge tools, thankyou, but Consistent and same are hardly adjectives that can be used to describe leftover garbage.
@Athar I wasn't asked this time. Perhaps you were reading a different thread.
Anyway gentlemen. Thanks for your opinions. Sorry if I put some noses out of joint
Sorry if I "Jump in"... But it looks like there was a little flame war here.
Moschops already told the answer. I don't see why you are still arguing about the answer. It's not a random number. It's a specific value depending on your Compiler/OS. Let me say, I already knew this from last year (You clearly can see the hex value in the MSVS's debugger... And it's not a random value). Only a few compilers don't clean up the "Leftover garbage" (I'm not even sure about this). The last 8 posts are almost completely useless, from my Point of View.
I guess simple little me got confused when the answer from mos was both "leftover stuff" (referring to the previous comment--leftover garbage) which would be different every time, and consistently setting uninitialized variables to the same value which, due to its bizzare value, is a good indication to the programmer as to its unitinitialized state.
This debate is, at best, symantical at this point.
So I have the answer to my question for which I will again thank you all and again appologize if I offended you