C ++:单位化变量垃圾 [英] C++: Unitialized variables garbage
本文介绍了C ++:单位化变量垃圾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int myInt;
cout<< myInt; //像429948之类的垃圾等
如果我在C ++中输出和/
- 来自最后一个用户的内存中的实际值?
例如:程序A关闭,它有一个int 1234
在 0x1234
- >我运行我的程序,
myInt
获取地址 0x1234
> 1234
- 是否只是随机垃圾?
不在随机 - 即绝对任意的垃圾,甚至没有任何保证随机性 - 编译器和运行时系统允许有绝对的任何东西(一些系统可能总是给零,其他可能给出任意不同的值,等等)。
int myInt;
cout << myInt; // Garbage like 429948, etc
If I output and/or work with unitialized variables in C++, what are their assumed values?
- Actual values in the memory from the "last user"?
e.g.: Program A is closed, it had an int with the value 1234
at 0x1234
-> I run my program, myInt
gets the address 0x1234
, I output it like above -> 1234
- Is it just random garbage?
解决方案
"Random garbage" but with emphasis on "garbage", not on "random" -- i.e., absolutely arbitrary garbage without even any guarantee of "randomness" -- the compiler and runtime systems are allowed to have absolutely anything there (some systems may always give zeros, other might give arbitrary different values, etc, etc).
这篇关于C ++:单位化变量垃圾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文