且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我不能初始化一个变量大小的数组?

更新时间:2022-06-18 00:02:42


  • 数组的大小必须是一个整型常量前pression。

  • 一个不可分割的文字是一个整型常量前pression。 ( INT ARR [5];

  • 以恒定的前pression初始化常量积分变是一个不断前pression。 ( const int的J = 4; const int的我=焦耳; int类型的[I];

与非恒定的前pression初始化一个常变量不是一个常量前pression

A constant variable initialized with a non-constant expression is not a constant expression

 int x = 4;  // x isn't constant expression because it is not const
 const int y = x; //therefore y is not either
 int arr[y]; //error)