部分初始化C中的数组默认值 [英] Partly initialized array default values in C
问题描述
我有一个关于部分初始化数组的问题。我将给出一个代码示例:
int array [20] = {[10] = 55};
编译器吗给予我任何保证,其他价值(指数10除外)会有一些特殊价值吗?我读过,当使用C99时,其他值将为0,但如果我没有指定任何标准怎么办?
您好,我有一个关于部分初始化数组的问题。我将给出一个代码示例:
int array [20] = {[10] = 55};
编译器吗给予我任何保证,其他价值(指数10除外)会有一些特殊价值吗?我读过,当使用C99时,其他值将为0,但如果我没有指定任何标准怎么办?
嗯?你是什么意思你没有指定任何标准?
如果你指定一个初始化者,即使它是空的(即{}),它会将未初始化的值默认为0或NULL(所有CPU上的NULL都不一定意味着0)。
Adrian
这是什么类型的代码? ?
展开 | 选择 | Wrap | 行号
嗯?你是什么意思你没有指定任何标准?
Adrian
我的意思是如果没有-std开关编译它
Hi, I have a question concerning partly initialized array. I''ll give an example of code:
int array[20] = {[10] = 55};
Does compiler grants me any assurance, that other values (except with index 10) will have some particular value? I''ve read, that when using C99, other values will be 0, but what if I don''t specify any standard?解决方案Hi, I have a question concerning partly initialized array. I''ll give an example of code:
int array[20] = {[10] = 55};
Does compiler grants me any assurance, that other values (except with index 10) will have some particular value? I''ve read, that when using C99, other values will be 0, but what if I don''t specify any standard?Huh? What do you mean you don''t specify any standard?
If you specify an initialiser, even if it is empty (i.e. {}) it will default the uninitialised values to 0 or NULL (NULL doen''t necessarly mean 0 on all CPUs).
Adrian
What kind of code is this??
Expand|Select|Wrap|Line Numbers
Huh? What do you mean you don''t specify any standard?
AdrianI meant if compile it without -std switch
这篇关于部分初始化C中的数组默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文