+ 3

Why does these code show these number?

So today i was just messing with my CodeBlocks IDLE. I just thought what would this code do. I expected it to show an error. #include <iostream> using namespace std; int main() { int x; cout<<x; } Output:- Some random Numbers like (4232030) which always start from 4. The number changes with change in PC, or if i enter <<endl; at last. You can even try these with double, float, char, string Why does this happen?

16th Jul 2017, 8:35 AM
Ritik Pal
Ritik Pal - avatar
3 Respostas
16th Jul 2017, 8:39 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
@Hatsy Rei Actually on some modern operating systems any memory that is not initialized is set to the value of a breakpoint or a special value, not just garbage. This is to prevent the memory from being executed for security and safety reasons. It's also done by compilers for the stack for the same reason
16th Jul 2017, 9:12 AM
aklex
aklex - avatar