类中的数组默认初始化为什么数?
  • 板块学术版
  • 楼主wmsx1
  • 当前回复11
  • 已保存回复11
  • 发布时间2023/9/8 15:49
  • 上次更新2023/11/2 22:21:02
查看原帖
类中的数组默认初始化为什么数?
389708
wmsx1楼主2023/9/8 15:49

求助

如题,出现了以下的几种情况:

  • 当 N=5 时, 类中数组初始化均为随机,比较好理解。

  • 但是当 N=20000+5 时, 遍历数组 q,tmp得到的值均为0。

    但是对于数组dp,它的前一部分是0,大概从 18000 开始出现随机的初始化

代码

可以使用洛谷的 IDE 跑跑看。

#include <bits/stdc++.h>
using namespace std;
const int N=20000+5;
class Test
{
private:
    int q[N];
    int tmp[N];
    int dp[N];
public:
    
    void print()
    {
        for(auto it:q)
        {
            cout<<it<<endl;
        }
    }
};


int main()
{
    ios::sync_with_stdio(false);
    Test A;
    A.print();
}
2023/9/8 15:49
加载中...