C ++:未初始化的变量垃圾 [英] C++: Uninitialized variables garbage

查看:66
本文介绍了C ++:未初始化的变量垃圾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int myInt;
cout << myInt; // Garbage like 429948, etc

如果我在C ++中输出和/或使用未初始化的变量,它们的假定值是什么?

If I output and/or work with uninitialized variables in C++, what are their assumed values?

  • 最后一个用户"在内存中的实际值?

例如:程序A已关闭,它在0x1234处具有一个值为1234的整数->运行我的程序,myInt获取地址0x1234,我像上面一样输出它-> 1234

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

  • 这只是随机垃圾吗?

推荐答案

随机垃圾",但强调垃圾",强调随机"–即,绝对任意的垃圾,甚至不能保证随机性"–允许编译器和运行时系统在其中具有绝对的任何内容(某些系统可能始终提供零,其他系统可能提供任意不同的值,依此类推,等等).

"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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆