+ 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?
3 Respostas
+ 9
Uninitialised variables store garbage values.
https://stackoverflow.com/questions/15326611/how-garbage-values-are-assigned-to-variables-in-c
+ 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