有没有更好的方法来初始化C中分配的数组?

如何用另一种(也许更短的)方式写这个?
有没有更好的方法来初始化C中分配的数组?
int main(void) {
   int* a;
   a = new int[10];
   for (int i=0; i < 10; ++i) a[i] = 0;
}

解决方法

int *a =new int[10](); // Value initialization

ISO C第8.5 / 5节

To value-initialize an object of type T means:

— if T is a class type (clause 9) with a user-declared constructor (12.1),then the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor);

— if T is a non-union class type without a user-declared constructor,then every non-static data member and base-class component of T is value-initialized;

— if T is an array type,then each element is value-initialized;

otherwise,the object is zero-initialized

对于零初始化,值初始化和认初始化之间的差异,请阅读this

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...