数组成员的值不合逻辑地更改 [英] Value of array member changes illogically

查看:69
本文介绍了数组成员的值不合逻辑地更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经注意到,当我声明一个数组时,

I noticed once that when I declare an array,

int arr[10];

一段时间后,数组成员的值发生变化,尽管在一段时间内没有任何影响。
然后我将动态分配与 new一起使用,问题就解决了。我认为应该动态声明所有内容。但这不应该是真的。逻辑上可能是什么原因?

after a while the value of array member changes although nothing affects it during a period. Then I made use of dynamic allocation with "new" and the problem solved. I thought that everything should be declared dynamically. But this shouldnt be true. What may be a logical reason?

推荐答案

原因可能有以下几种:


  • 初始化数组成员(如果它在本地存储中),或者如果它不包含任何随机值,则初始化它。

  • 您可能会覆盖某些数组的边界

  • 您以某种神奇的方式破坏了堆栈。

这篇关于数组成员的值不合逻辑地更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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