更新时间:2021-08-27 21:05:30
静态初始化数组的语法使用大括号,如下所示:
The syntax to statically initialize an array uses curly braces, like this:
int array[10] = { 0 };
这将对数组进行零初始化.
This will zero-initialize the array.
对于多维数组,你需要嵌套的花括号,像这样:
For multi-dimensional arrays, you need nested curly braces, like this:
int cipher[Array_size][Array_size]= { { 0 } };
请注意,Array_size
必须是编译时常量才能使其正常工作.如果 Array_size
在编译时未知,则必须使用动态初始化.(***是 std::vector
).
Note that Array_size
must be a compile-time constant for this to work. If Array_size
is not known at compile-time, you must use dynamic initialization. (Preferably, an std::vector
).