C 静态数组初始化 - 我需要多详细? [英] C Static Array Initialization - how verbose do I need to be?
本文介绍了C 静态数组初始化 - 我需要多详细?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要初始化一个全为零的 int 数组,是否需要使用:
To initialize an int array with all zeros, do I need to use:
int foo[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
或者,这行得通吗:
int foo[10] = {0};
推荐答案
int foo[10] = {0};
这很好:)
请注意,如果您执行以下操作:
Note that if you do the following:
int foo[10] = {1};
只有数组的第一个元素会用非零数字初始化,而其余的元素会用零初始化.
Only the first element of the array will be initialized with the non-zero number whereas the rest will be initialized with zeros.
这篇关于C 静态数组初始化 - 我需要多详细?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文