/*That's not quite true (you should almost certainly get yourself an alternative reference), you are allowed an empty initializer (()) which will value-initialize the array but yes, you can't initialize array elements individually when using array new. */
//动态申请数组
int* p = new int[5](); // array initialized to all zeroint* q = new int[5]; // array elements all have indeterminate value
/*There's no fundamental reason not to allow a more complicated initializer it's just that C++03 didn't have a grammar construct for it. In the next version of C++ you will be able to do something like this.*/
int* p = new int[5] {0, 1, 2, 3, 4};
C++数组初始化与新特性
本文探讨了C++中数组的两种初始化方式:使用空初始化列表将数组元素设置为0,以及不指定初始值导致的不确定状态。此外,还介绍了即将在新版C++中推出的复杂初始化语法。

被折叠的 条评论
为什么被折叠?



