如何初始化没有一个循环数组在C什么? [英] How to initialize an array to something in C without a loop?
本文介绍了如何初始化没有一个循环数组在C什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以说我有像
int arr[10][10];
现在我想初始化这个数组为0的所有元素我怎么能做到这一点没有循环或指定的每个元素?
Now i want to initialize all elements of this array to 0. How can I do this without loops or specifying each element?
请注意,如果这个问题对C
Please note that this question if for C
推荐答案
快速正肮脏的解决方案:
The quick-n-dirty solution:
int arr[10][10] = { 0 };
如果您初始化的任何的数组元素,C将默认,初始化,你不明确指定任何元素。所以上面的code初始化为零的第一要素,而C设置其它所有元素为零。
If you initialise any element of the array, C will default-initialise any element that you don't explicitly specify. So the above code initialises the first element to zero, and C sets all the other elements to zero.
这篇关于如何初始化没有一个循环数组在C什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文