C++不初始化

来源:互联网 发布:ubuntu查看显卡状态 编辑:程序博客网 时间:2024/06/06 07:21

今天看到一个不初始化造成的不确定后果,很奇怪,特记录下来:


#include <iostream>  using namespace std;   void a()  {      volatile int array[10]; //可以去掉 volatile      for (int i = 0; i < 10; i++)          array[i] = i;  }    void b()  {      int array[10];           //这里没有初始化,值是不确定的~      for (int i = 0; i < 10; i++)          cout << array[i];  }    int main()  {      a();      b();      system("pause");      return 1;  }  

输出结果是123456789

0 0