0

常规数组创建时需要初始化吗?如果它是默认初始化的,是否无法更改数组中的元素?

创建二维数组时,我看到的所有示例都使用动态内存。是不是因为动态分配的二维数组不需要初始化。声明常规二维数组后是否可以填充数组元素?

4

1 回答 1

0
  • no, a static array needs no initialization ("needs" meaning you don't have to give one. Of course you should consider initial values depending on your problem).
  • You can change all values always. Just use e.g. my_array[2][3] = 42 to assign the value.
  • people are using dynamically alocated memory whenever the array size is unknown at compile time or changes over time. Allocated memory is not initialized, therefore it's your responsibility to provide good default values.

Read more at http://www.cplusplus.com/doc/tutorial/arrays/

于 2013-09-17T21:06:22.673 回答