I would like to initialize an array of strings with
I would like to initialize an array of strings with \0. Is it right to do it like this?
我想用\ 0初始化一个字符串数组。这样做是对的吗?
char first[1024][1024] = {'\0'};
2 个解决方案
#1
2
For a 2d array is better to use:
对于2d阵列最好使用:
char first[1024][1024] = {{'\0'},{'\0'}};
or better yet (as suggested by @haccks):
或者更好(正如@haccks所建议的那样):
char first[1024][1024] = {{'\0'}};
in order to avoid warnings.
为了避免警告。
#2
-1
If it is a static array, say, a global array, you do not need to do any initialization and the values of the array are set to 0 by default.
如果它是一个静态数组,比如一个全局数组,则不需要进行任何初始化,默认情况下该数组的值设置为0。
. Is it right to do it like this?I would like to initialize an array of strings