初始化动态数组元素为零

初始化动态数组元素为零

问题描述:

对于一个固定的阵列,

  // will initialize the missing elements to 0 as well
   A[max_row][max_col] = {0,} 

我们能在动态数组(多维的,尤其是)?做到这一点。

Can we achieve this in dynamic arrays (multidimensional, in particular)?

侧的问题:如果我们不能,我们不得不使用嵌套循环,那么如何上面相比嵌套循环初始化的伎俩初始化时间?

Side question: if we can't, and we are forced to use nested loop, then how does the initialization time of the trick above compared to nested loop initialization?

我不想矢量,否则这个问题是没有意义的。谢谢你的提醒:)

I don't want to vector, otherwise this question is meaningless. Thanks for the advise :)

如果你这样做:新的INT [n]()/ *注括号* / ,然后它们都是零初始化的。

If you do this: new int[N]() /* note parenthesis */, then they are all zero initialized.

您真的应该使用的std ::矢量,虽然