为什么内存位置分配的是垃圾值? [英] Why are memory locations assigned garbage values?

查看:178
本文介绍了为什么内存位置分配的是垃圾值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是想知道为什么垃圾值存储在内存空间。为什么不让内存填充零。有什么特别的原因吗?

I always wondered why there are garbage values stored in a memory space. Why cant the memory be filled with zeros. Is there a particular reason?

例如:

int a ;
cout<<a //garbage value displayed


推荐答案

分配零需要时间,并不总是程序员想要做的。考虑这个:

Assigning zeros takes time and is not always what the programmer wants to do. Consider this:

int a;
std::cin >> a;

为什么要浪费时间在内存中加载零,当你要做的第一件事情是存储一个不同的价值吗?

Why waste time loading a zero into the memory when the first thing you are going to do is store a different value there?

这篇关于为什么内存位置分配的是垃圾值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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