Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In c++, I know that when a memory space is deallocated with a 'delete' operator and then one try to fetch what the pointer points to after the deletion, it always gives an unpredictable output. Although this output can not be predicted, however, it's always a 7-digit integer. Why?

share|improve this question
1  
It's not always a 7 digit integer. – delnan Apr 23 at 12:09
How isn't it after I have run some programs countlessly and yet they always give a 7-digit number? If it isn't, please give me an example that I will run to see that what I thought isn't true. Thanks. – YYG Apr 23 at 12:13
2  
It may happen to be a 7-digit number on your system for whatever reasons. Note that "undefined" is not the same as "random": it is perfectly valid behavior for a C++ implementation to fill memory with all-zero (or even all 23) upon deallocation. – tdammers Apr 23 at 12:18
Okay tdammers, if I got you right you mean I should always be getting a 7-digit number in my system, or perhaps it can change sometime (though it never does)? – YYG Apr 23 at 12:22
It can change very easily. Even a minor update to anything involved in running your program (compiler, libraries, OS, etc.) can change it. In fact, it may even change between runs of the same binary (for examples, memory addresses often do vary between runs). There is literally nothing you can predict, both in theory (it's undefined behavior by the standard, period) and in practice (you'd need intimate knowledge of the entire state of your system and every program involved). – delnan Apr 23 at 12:29
show 4 more comments

closed as not a real question by jk., delnan, Jalayn, MichaelT, pdr Apr 23 at 13:35

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

Browse other questions tagged or ask your own question.